I am trying to bind several files into a single one and also generate a list which returns to the number of rows for each individual file. I can bind those files into one, but I failed to generate this list. Could anyone help me? Thanks in advance.
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