r格式具有随机换行符并导出的csv

时间:2018-10-09 18:55:39

标签: r csv

我有csv文件,由于某些原因,这些文件在某些​​代码后会出现随机换行符:

我可以在R中很好地读取此文件,但我想知道是否有一种方法可以创建没有随机换行符的输出?在其他程序中导入该文件会造成416换行的问题。

ID,滥用,AbuseHistoryOfAbuse,AbuseCurrentlyInAbusive,AbuseHistoryOfCPS,AbuseImminentRisk,AbuseInterventionCodes,酒精,AlcoholCurrentlyInTreatment,AlcoholSuspectUse,AlcoholAdmitsUse,AlcoholInterventionCodes,哮喘,AsthmaHistory,AsthmaInterventionCodes,BarriersToService,BarriersExperiencing,BarriersHistoryOf,BarriersToServiceInterventionCodes,BasicNeeds,BasicFood,BasicFoodLimitedAccess,BasicFoodNoWIC,BasicFoodNoDHS ,BasicHousing,BasicHousingHasRegular,BasicHousingHomelessWith,BasicHousingHomelessWithout,BasicTransportation,BasicTransportationNoneLimited,BasicOther,BasicNeedsInterventionCodes,母乳喂养,BreastfeedingPrenatal,BreastfeedingInterventionCodes,BreastHealth,BreastHealthInterventionCodes,糖尿病,DiabetesHistoryGestational,DiabetesHistoryDiabetes,DiabetesInterventionCodes,药品,DrugsType,DrugsUse,DrugsInterventionCodes,计划生育,FamilyPlanningNoPlans,FamilyPlanningInterventionCodes,高血压,高血压史高血压,高血压史先兆子痫,高血压ionInterventionCodes,营养,NutritionInterventionCodes,ChronicDisease,ChronicDiseaseHistoryOther,ChronicDiseaseInterventionCodes,牙周,PeriodontalNoVisit,PeriodontalInterventionCodes,PersonalGoals,PersonalGoalsInterventionCodes,吸烟,SmokingUse,SmokingInterventionCodes,社会支持,SocialSupportInterventionCodes,STD,STDDiscloseSTD,STDDiscloseHIV,STDInterventionCodes,应力,PrenatalEDSScore,PostnatalEDSScore,StressScore,StressAll,压力适中,压力历史心理健康,压力历史Baby Blues,压力报告压力,压力当前被治疗,压力不跟随,压力背负自杀,压力干预代码,压力健康,压力健康干预代码 0001,FALSE,FALSE,FALSE,FALSE,FALSE,NA,FALSE,FALSE,FALSE,FALSE,NA,FALSE,FALSE,NA,TRUE,FALSE,TRUE,411

416,TRUE,TRUE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,5F11

5T42

,是,不是母乳喂养,否,假,假,假,假,假,假,假,假,假,假,假,假,假,假,假,假,假,假,假,FALSE,NA,FALSE,FALSE,NA,FALSE,NA,FALSE,NA,NA,TRUE,2041,FALSE,FALSE,FALSE,NA,FALSE,NA,NA,NA,FALSE,FALSE,FALSE,FALSE,FALSE ,FALSE,FALSE,FALSE,NA,FALSE,NA

我添加了有助于显示更多内容的屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

正如您提到的,R确实知道如何在读取CSV文件时跳过空行。这意味着结果数据帧将不包含意外的换行符,因此,如果您再次将其写入CSV,同样,它也将没有随机的换行符:

temp <- read.csv('table_with_line_breaks.csv')
write.csv(temp, 'table_without_line_breaks.csv', row.names = FALSE, quote = FALSE)