0
複数のファイルを1つのファイルにバインドしようとしていますが、個々のファイルの行数に戻るリストを生成しようとしています。これらのファイルを1つにバインドできますが、このリストの生成に失敗しました。誰か助けてくれますか?前もって感謝します。詳細/議論についてファイルを1つにバインドしてタグを生成する
aa = c(1:3) #files with .1 or .2 suffix
bb = paste0(datasource,"file.",aa) # paste all those files into one
merge.data = read.table(bb[1]) # read the first file as a data.frame
n = rnow(merge.data) # this will be the number of row under the first file
for (i in 2:n){
new.data = read.table(bb[i]) # read all following files
merge.data = rbind(merge.data, new.data) # bind those files into a single one
}
merge.data # this the whole data.frame contains all original files' data
yy = paste0(datasource,"file.",aa)
merge.data = data.frame()
##### I would like to add another variable np, which is a list representing the number of rows for each individual file before merge
np = NULL
for (i in 1:n){
merge.data[i] = read.table(bb[i])
np[i] = nrow(merge.data[i])
merge.data = rbind(merge.data[i])
}
np
merge.data
コードは非常にきちんと役立ちます。どうもありがとうございました! –