[R] Merging multiple data sets

Bharat Warule bwarule at gmail.com
Wed May 16 15:51:06 CEST 2012


Hello R user,

I have four data sets in dir "D:/Bharat Warule/Rdata_file" which are
output_data_prod_1.rda, output_data_prod_2.rda, output_data_prod_3.rda,
output_data_prod_4.rda.
Each data set is huge size like number of rows 343297 and columns are near
to 50. 

For example:

x1 <- data.frame(x11=c(1,2,3,4,5),x112=c(10,10,10,10,10))
x2 <- data.frame(x11=c(1,2,3,4,5),x122=c(20,20,20,20,20))
x3 <- data.frame(x11=c(1,2,3,4,5),x132=c(30,30,30,30,30))
x4 <- data.frame(x11=c(1,2,3,4,5),x142=c(40,40,40,40,40))
x5 <- data.frame(x11=c(1,2,3,4,5),x152=c(50,50,50,50,50))

for(i in 1:5){
name <- paste('x',i,sep='')
name1 <- paste(name,"rda",sep='.')   
save(name, file = name1)
}


I want merge this data sets into one data set but I don’t know where I am
going wrong?

Please help me. Thanks for your help.  

subsetname <-  "x1"
file_no    <-   4
output_data_prod    <-   data.frame()

for(n in 1:file_no){
 myfile    <- gsub("( )", "", paste(subsetname , "_", n,".rda"))
 temp_data <- load(file = myfile)
 data_22   <- get(temp_data)

 if(dim(output_data_prod)[1]==0){output_data_prod <- data_22  
      }else{
  output_data_prod <- merge(inData1 = output_data_prod,
	inData2 = data_22 ,type = "inner", all=FALSE ,
		by =c("x11"))}
	
}


-----
Bharat Warule 
Cypress Analytica ,
Pune
--
View this message in context: http://r.789695.n4.nabble.com/Merging-multiple-data-sets-tp4630244.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list