rbind multiple data sets (.csv)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

rbind multiple data sets (.csv)

zaq0718
This post has NOT been accepted by the mailing list yet.
Hello,
I am trying to rbind two data sets into one data set.But my two data sets are from different folders, which are C:\Users\yw12\Desktop\data 3\C1 and C:\Users\yw12\Desktop\data 3\C2. And each folder has 100 data sets. In the C1 folder, it has C1_1,C1_2,...,C1_100;in the C2 folder , it has C2_1,C2_2,...,C2_100.
I want to rbind C1_1 vs C2_1,C1_2, vs C2_2,....

All of data sets are .csv.
How can I do that ?
Than you
Reply | Threaded
Open this post in threaded view
|

Re: rbind multiple data sets (.csv)

arun kirshna
Hi,
If your working directory is "data 3" which has only two folders C1 and C2.
May be this helps:

lsF1 <- list.files(recursive=TRUE)
lst1 <- lapply(split(lsF1,gsub(".*\\_(\\d+)\\..*","\\1",lsF1)),function(x) do.call(rbind,lapply(x,function(y) read.csv(y, header=TRUE))))

A.K.



Hello,
I am trying to rbind two data sets into one data set.But my two data sets are from different folders, which are C:\Users\yw12\Desktop\data 3\C1 and C:\Users\yw12\Desktop\data 3\C2. And each folder has 100 data sets. In the C1 folder, it has C1_1,C1_2,...,C1_100;in the C2 folder , it has C2_1,C2_2,...,C2_100.
I want to rbind C1_1 vs C2_1,C1_2, vs C2_2,....

All of data sets are .csv.
How can I do that ?
Than you

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: rbind multiple data sets (.csv)

zaq0718
This post has NOT been accepted by the mailing list yet.
Hello, Thank you!
What should I put in split(lsF1,gsub(".*\\_(\\d+)\\..*","\\1",lsF1)? If my two paths are C:\Users\yw12\Desktop\data 3\C1 and C:\Users\yw12\Desktop\data 3\C2