I have 2 data sets. File1 and File2. Some records are common to both data sets. For those common records I want get the difference between d_x1z1= z1-x1 and d_x2z2= z2-x2. File1<- data.frame(var = c(561,752,800,900), x1= c(23,35,40,15), x2c(125,284,280,347)) File2<- data.frame(var = c(561,752,800,1001), z1= c(43,45,40,65), z2c(185,299,280,310)) Record 900 15 347 appears only in File1 Record 1001 65 310 appears only in File2 File3 should look like as follows File3 var x1 x2 z1 z2 d_x1z1 d_x2z2 561 23 125 43 165 20 40 752 35 284 45 299 8 15 800 40 280 40 280 0 0 900 15 347 NA NA NA NA 1001 NA NA 65 310 NA NA How do I get those record not common in both data sets ? merge( File1,File2) gave me only for common "var"
?merge Pay attention to the all-whatever parameters. -- Sent from my phone. Please excuse my brevity. On June 2, 2016 7:04:47 PM PDT, Ashta <sewashm at gmail.com> wrote:>I have 2 data sets. File1 and File2. Some records are common to both >data sets. For those common records I want get the difference between >d_x1z1= z1-x1 and d_x2z2= z2-x2. > >File1<- data.frame(var = c(561,752,800,900), x1= c(23,35,40,15), x2>c(125,284,280,347)) >File2<- data.frame(var = c(561,752,800,1001), z1= c(43,45,40,65), z2>c(185,299,280,310)) > >Record 900 15 347 appears only in File1 >Record 1001 65 310 appears only in File2 > >File3 should look like as follows > >File3 >var x1 x2 z1 z2 d_x1z1 d_x2z2 >561 23 125 43 165 20 40 >752 35 284 45 299 8 15 >800 40 280 40 280 0 0 >900 15 347 NA NA NA NA >1001 NA NA 65 310 NA NA > >How do I get those record not common in both data sets ? >merge( File1,File2) gave me only for common "var" > >______________________________________________ >R-help at 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]]
Thank you Jeff. Solved. On Fri, Jun 3, 2016 at 12:47 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> ?merge > > Pay attention to the all-whatever parameters. > -- > Sent from my phone. Please excuse my brevity. > > On June 2, 2016 7:04:47 PM PDT, Ashta <sewashm at gmail.com> wrote: >> >> I have 2 data sets. File1 and File2. Some records are common to both >> data sets. For those common records I want get the difference between >> d_x1z1= z1-x1 and d_x2z2= z2-x2. >> >> File1<- data.frame(var = c(561,752,800,900), x1= c(23,35,40,15), x2>> c(125,284,280,347)) >> File2<- data.frame(var = c(561,752,800,1001), z1= c(43,45,40,65), z2>> c(185,299,280,310)) >> >> Record 900 15 347 appears only in File1 >> Record 1001 65 310 appears only in File2 >> >> File3 should look like as follows >> >> File3 >> var x1 x2 z1 z2 d_x1z1 d_x2z2 >> 561 23 125 43 165 20 40 >> 752 35 284 45 299 8 15 >> 800 40 280 40 280 0 0 >> 900 15 347 NA NA NA NA >> 1001 NA NA 65 310 NA NA >> >> How do I get those record not common in both data sets ? >> merge( >> File1,File2) gave me only for common "var" >> >> ________________________________ >> >> R-help at 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.