在R中,在csv

时间:2016-03-08 13:52:35

标签: r csv read.table eol read.csv

我循环遍历数百个csv文件并将其读入r数据帧(read.csv())。某些csv文件缺少行尾(EOL)字符。这会产生错误,"incomplete final line found by readTableHeader."在收到此错误后,我没有从该csv获得任何所需的数据。

以下步骤解决了单个csv的问题:   1.打开文件   2.导航到文件的最后一行   3.将光标放在该行的末尾   4.按返回   5.保存文件

但是,我需要将这种方法融入我的循环中。我有100多个文件格式如下面的例子(只有少数人返回此错误)。我不能去每个csv并修复上述步骤。有什么建议吗?

用于读表的函数: AdamTurb <- read.csv("myfile.csv")

这是myfile.csv的内容: OrganizationIdentifier,OrganizationFormalName,ActivityIdentifier,ActivityTypeCode,ActivityMediaName,ActivityMediaSubdivisionName,ActivityStartDate,ActivityStartTime /时间,ActivityStartTime / TimeZoneCode,ActivityEndDate,ActivityEndTime /时间,ActivityEndTime / TimeZoneCode,ActivityDepthHeightMeasure / MeasureValue,ActivityDepthHeightMeasure / MeasureUnitCode,ActivityDepthAltitudeReferencePointText,ActivityTopDepthHeightMeasure / MeasureValue,ActivityTopDepthHeightMeasure / MeasureUnitCode, ActivityBottomDepthHeightMeasure / MeasureValue,ActivityBottomDepthHeightMeasure / MeasureUnitCode,ProjectIdentifier,ActivityConductingOrganizationText,MonitoringLocationIdentifier,ActivityCommentText,SampleAquifer,HydrologicCondition,HydrologicEvent,SampleCollectionMethod / MethodIdentifier,SampleCollectionMethod / MethodIdentifierContext,SampleCollectionMethod /方法名,SampleCollectionEquipmentName,ResultDetectionConditionText,CharacteristicName,ResultSampleFractionText,ResultMeasureValue,ResultMeasure / MeasureUnitCode,男easureQualifierCode,ResultStatusIdentifier,StatisticalBaseCode,ResultValueTypeName,ResultWeightBasisText,ResultTimeBasisText,ResultTemperatureBasisText,ResultParticleSizeBasisText,PrecisionValue,ResultCommentText,USGSPCode,ResultDepthHeightMeasure / MeasureValue,ResultDepthHeightMeasure / MeasureUnitCode,ResultDepthAltitudeReferencePointText,SubjectTaxonomicName,SampleTissueAnatomyName,ResultAnalyticalMethod / MethodIdentifier,ResultAnalyticalMethod / MethodIdentifierContext,ResultAnalyticalMethod /方法名,MethodDescriptionText, LaboratoryName,AnalysisStartDate,ResultLaboratoryCommentText,DetectionQuantitationLimitTypeName,DetectionQuantitationLimitMeasure / MeasureValue,DetectionQuantitationLimitMeasure / MeasureUnitCode,PreparationStartDate,的ProviderName NARS_WQX,EPA国家水产资源调查,NARS_WQX-QWCH:0452:1:070615:P,Sample-Routine,Water ,, 2007-06-15,00:00:00 ,,,,,,,,,,,, NARS_NLA2007; NARS_NLA2007_ECOREGION_SPL ,, NARS_WQX-NLA06608-0452, “VISIT_NO =” “1” “; SAMPLE_CATEGORY =” “P” “; INDXSAMP_CHEM =” “YES” “; SAMPLE_DEPTH =” “2” “; SAMPLE_ID_CHEM =” “502231” “; LAB_ID_CHEM =”“0710049”“; COMMENT_LAB_CHEM =”“未过滤样本中的实时生物。”“; DATE_FILTERED =”“2007-06-16”“; DATE_RECEIVED =”“2007-06-16”“; DATEFILT_ALERT =” “N”“; DATECHEM =”“2007-06-15”“”,,,, 2meterMPCA,NARS_WQX,综合水取样器,水取样器(其他),浊度,, 3.59,NTU ,,最终,,实际,, ,,,, “TURB_HT_ALERT =” “N” “; TURB_HT =” “3” “; TURB_RL_ALERT =” “N” “” ,,,,,,,,,,,,,,,,,, STORET NARS_WQX,EPA国家水产资源调查,NARS_WQX-QWCH:1083:1:070629:P,Sample-Routine,Water ,, 2007-06-29,00:00:00 ,,,,,,,,,,,, NARS_NLA2007; NARS_NLA2007_ECOREGION_SPL ,, NARS_WQX-NLA06608-1083, “VISIT_NO =” “1” “; SAMPLE_CATEGORY =” “P” “; INDXSAMP_CHEM =” “YES” “; SAMPLE_DEPTH =” “1.2” “; SAMPLE_ID_CHEM =” “503301” “; LAB_ID_CHEM =” “0710174” “; DATE_FILTERED =” “2007-06-30” “; DATE_RECEIVED =” “2007-06-30” “; DATEFILT_ALERT =” “N” “; DATECHEM =”“2007-06- 29“”“,,,, 2meterMPCA,NARS_WQX,综合水样采集器,水采样器(其他),浊度,27.6,NTU ,, Final ,, Actual ,,,,,,”TURB_HT_ALERT =“”N“”; TURB_HT = “” 3 “”; TURB_RL_ALERT = “” N “”” ,,,,,,,,,,,,,,,,,, STORET

谢谢!

0 个答案:

没有答案