[R] Merging multiple data sets

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed May 16 17:49:46 CEST 2012



On 16.05.2012 15:51, Bharat Warule wrote:
> 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)

To fix this part, use:

save(list = 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"))

To match the above:

  myfile    <- gsub("( )", "", paste(subsetname , n, ".rda", sep=""))

>   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,

Nonsense, the arguments of merge are called x and y rather than inData1 
and inData2.

Uwe Ligges

> 	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.
>
> ______________________________________________
> 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.



More information about the R-help mailing list