我想通过读取一个csv文件中的每一天来构造一个数据框。我的每日csv文件包含相同行数的字符,双精度和整数列。我知道任何给定月份的最大行数,并且每个csv文件的列数保持不变。我环路通过与fileListing,其中包含csv文件名列表中选择一个月份的每一天(比方说,一月份):从read.csv中逐步追加数据
output <- matrix(ncol=18, nrow=2976)
for (i in 1 : length(fileListing)){
df = read.csv(fileListing[ i ], header = FALSE, sep = ',', stringsAsFactors = FALSE, row.names = NULL)
# each df is a data frame with 96 rows and 18 columns
# now insert the data from the ith date for all its rows, appending as you go
for (j in 1 : 18){
output[ , j ] = df[[ j ]]
}
}
对不起,已经修订我的问题,我想通了,它(杜)的一部分,但是我应该使用rbind逐步在数据框的底部插入数据,还是很慢?
谢谢。
BSL
你可能最好将它们全部读入列表中,并使用'do.call(rbind.data.frame,data)'将它们一次全部组合。 –