I would like to read data from two different folder and then combine this together the code which I have tried are as follows setwd("/Groups/data_first/") file_was <- list.files(path = ".", pattern = "v2.0.2.was", all.files FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) path<-c("/Groups/data_second/") file_wasaux2 <-list.files(path,pattern="v2.0.2.wasaux2") files<- 1 for ( i in files){ data1 <- read.table(file_was[i],header=TRUE) data2 <- read.table(paste(path1t, file_wasaux2[i],header=TRUE)) data <- cbind (data1,data2) } but I get error (Error in read.table(SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2, header = TRUE) : object 'SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2' not found) could somebody please tell me how to solve this problem? -- View this message in context: http://r.789695.n4.nabble.com/reading-files-from-two-folders-tp4511493p4511493.html Sent from the R help mailing list archive at Nabble.com.
Hi, On 03/28/2012 08:48 AM, uday wrote:> I would like to read data from two different folder and then combine this > together > the code which I have tried are as follows > setwd("/Groups/data_first/") > file_was <- list.files(path = ".", pattern = "v2.0.2.was", all.files > FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) > path<-c("/Groups/data_second/") > file_wasaux2 <-list.files(path,pattern="v2.0.2.wasaux2") > files<- 1 > for ( i in files){ > data1 <- read.table(file_was[i],header=TRUE) > data2 <- read.table(paste(path1t, file_wasaux2[i],header=TRUE)) > data <- cbind (data1,data2) > } > but I get error > (Error in read.table(SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2, header = TRUE) > : > object 'SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2' not found) > > could somebody please tell me how to solve this problem? >I assume that the problem is the following line:> data2 <- read.table(paste(path1t, file_wasaux2[i],header=TRUE))The default separator of paste is " ", see: ?paste that probably means that the file you want to read has a different name than what you actually provide as the file name. Just a guess, though.... Please let me add that it is probably not a good idea to call your data data. First, it is not very descriptive, meaning: you may have problems in the future to understand your own code. Second, a function of the same name exists already. Hope this helps, Roland
Hello, uday, there's presumably a typo in your code because you use path1t in> data2 <- read.table(paste(path1t, file_wasaux2[i],header=TRUE))and not path which you defined above. Hth -- Gerrit --------------------------------------------------------------------- Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner --------------------------------------------------------------------- On Tue, 27 Mar 2012, uday wrote:> I would like to read data from two different folder and then combine this > together > the code which I have tried are as follows > setwd("/Groups/data_first/") > file_was <- list.files(path = ".", pattern = "v2.0.2.was", all.files > FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) > path<-c("/Groups/data_second/") > file_wasaux2 <-list.files(path,pattern="v2.0.2.wasaux2") > files<- 1 > for ( i in files){ > data1 <- read.table(file_was[i],header=TRUE) > data2 <- read.table(paste(path1t, file_wasaux2[i],header=TRUE)) > data <- cbind (data1,data2) > } > but I get error > (Error in read.table(SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2, header = TRUE) > : > object 'SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2' not found) > > could somebody please tell me how to solve this problem? > > > -- > View this message in context: http://r.789695.n4.nabble.com/reading-files-from-two-folders-tp4511493p4511493.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. > >
Hi Hth -- Gerrit , thanks for reply sorry it was typo mistake , but I corrected that problem before . But the error is still same. setwd("/Groups/data_first/") file_was <- list.files(path = ".", pattern = "v2.0.2.was", all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) path<-c("/Groups/data_second/") file_wasaux2 <-list.files(path,pattern="v2.0.2.wasaux2") files<- 1 for ( i in files){ data1 <- read.table(file_was[i],header=TRUE) data2 <- read.table(paste(path, file_wasaux2[i],header=TRUE)) data <- cbind (data1,data2) } -- View this message in context: http://r.789695.n4.nabble.com/reading-files-from-two-folders-tp4511493p4511717.html Sent from the R help mailing list archive at Nabble.com.
Hi Hth -- Gerrit , I found the problem I added "sep" and one bracket was missing the new codes are as follows setwd("/Groups/data_first/") file_was <- list.files(path = ".", pattern = "v2.0.2.was", all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) path<-c("/Groups/data_second/") file_wasaux2 <-list.files(path,pattern="v2.0.2.wasaux2") files<- 1 for ( i in files){ data1 <- read.table(file_was[i],header=TRUE) data2 <- read.table(paste(path, file_wasaux2[i],sep=""),header=TRUE) data <- cbind (data1,data2) } data Cheers Uday -- View this message in context: http://r.789695.n4.nabble.com/reading-files-from-two-folders-tp4511493p4511809.html Sent from the R help mailing list archive at Nabble.com.