Re: [R] Merge several datasets into one
Hi Lily, I think below codes can work: f<- list.files("D:/output/test/your folde rname",full.names=TRUE,recursive=TRUE) files<- grep(".csv", f) files_merge<- data.frame() for (i in 1:length(f[files])){ data<- read.csv(file=f[files][i],header=TRUE, sep=",") files_merge<- rbind(files_merge,data) } Best, Lida On Thu, Jun 30, 2016 at 2:26 PM, lily li <chocol...@gmail.com> wrote: > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I put > these csv files in one folder, and use the lapply function, but it says > that cannot open file 'xx.csv'. These files have different names, but end > with .csv extension, and the files have the same header. Thanks for your > help. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] Merge several datasets into one
Hello, Maybe something like this. fls <- list.files(pattern = "*.csv") dat.list <- lapply(fls, read.csv) dat <- do.call(rbind, dat.list) Hope this helps, Rui Barradas Citando lily li <chocol...@gmail.com>: > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I put > these csv files in one folder, and use the lapply function, but it says > that cannot open file 'xx.csv'. These files have different names, but end > with .csv extension, and the files have the same header. Thanks for your > help. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.htmland provide commented, > minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] Merge several datasets into one
Lily Li <chocol...@gmail.com> wrote : I think you are going to have to give us some more detail. What commands did you execute? what are the names of the .csv files in your directory? Can you read one of them as asingle read.csv? > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I put > these csv files in one folder, and use the lapply function, but it says > that cannot open file 'xx.csv'. These files have different names, but end > with .csv extension, and the files have the same header. Thanks for your > help. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org > mailing list -- To UNSUBSCRIBE and more, see > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] Merge several datasets into one
Lily: If you mean that you have several csv files in a directory/folder on your computer and you are using lapply() to do something with them, then you do not have a clue about how R works and you need to go through some tutorials to learn. There are many good ones on the web. Some recommendations can be found here: https://www.rstudio.com/online-learning/#R We do expect posters here to have made some minimal effort to learn R basics before posting. If I have misunderstood, then you will either have to wait for a reply from someone with greater insight or explain yourself more clearly. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Jun 30, 2016 at 12:26 PM, lily li <chocol...@gmail.com> wrote: > Hi R users, > > I'd like to ask that how to merge several datasets into one in R? I put > these csv files in one folder, and use the lapply function, but it says > that cannot open file 'xx.csv'. These files have different names, but end > with .csv extension, and the files have the same header. Thanks for your > help. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] Merge several datasets into one
Hi R users, I'd like to ask that how to merge several datasets into one in R? I put these csv files in one folder, and use the lapply function, but it says that cannot open file 'xx.csv'. These files have different names, but end with .csv extension, and the files have the same header. Thanks for your help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.