R导入多个CSV文件

R导入多个CSV文件

本文介绍了R导入多个CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R中导入多个TSV文件(是: T SV).

I want to import multiple TSV Files (yes: TSV) in R.

通过使用以下选项,可以读取单个带有选定的特殊列的文件:

Reading a single file with an selection of spacific columns works well by using:

data00<-read.csv(file = '/Volumes/2018/06_abteilungen/bi/analytics/tools/adobe/adobe_analytics/adobe_analytics_api_rohdaten/api_via_data_feed_auf_ftp/beispiel_datenexporte_data_feed/01sssamsung4de_20180501-000000.tsv',
                 sep ="\t",
             fill = TRUE,
             quote='',
             header = FALSE
)[ ,c(287, 288, 289, 290, 291, 292, 293, 304, 370, 661, 662, 812, 813,     994, 995, 1002)]

现在,我想导入多个文件并将它们组合为一个数据框:

Now i want to import multiple files and combine them to a single dataframe:

setwd('/Volumes/2018/06_abteilungen/bi/analytics/tools/adobe/adobe_analytics/adobe_analytics_api_rohdaten/api_via_data_feed_auf_ftp/beispiel_datenexporte_data_feed/import_r')

temp <- list.files(pattern="*.tsv")

test_data <- lapply(temp, read.csv,
sep ="\t",
fill = TRUE,
quote='',
header = FALSE
)[ ,c(287, 288, 289, 290, 291, 292, 293, 304, 370, 661, 662, 812, 813, 994, 995, 1002)]

最后一个查询给我一个例外,它不起作用:Fehler in lapply(temp,read.csv,sep ="\ t",fill = TRUE,quote =",标头= FALSE)[,:falsche Anzahl von Dimensionen(翻译:错误的尺寸计数)

Last querie gives my an exception and doesnt work:Fehler in lapply(temp, read.csv, sep = "\t", fill = TRUE, quote = "", header = FALSE)[, : falsche Anzahl von Dimensionen (translation: wrong count of dimensions)

当我处理所有列时,它会起作用:

When I take all columns, it works:

test_data <- lapply(temp, read.csv,
sep ="\t",
fill = TRUE,
quote='',
header = FALSE
)

推荐答案

您正在索引数据帧列表,而不是数据帧本身.试试:

You are indexing the list of data frames, and not the dataframes themselves. Try:

test_data <- lapply(temp,function(x){
  read.csv(file = x,
                 sep ="\t",
                 fill = TRUE,
                 quote='',
                 header = FALSE
  )[ ,c(287, 288, 289, 290, 291, 292, 293, 304, 370, 661, 662, 812, 813,994, 995, 1002)]
}
)

这篇关于R导入多个CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:16