[R] Prob with merge

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Nov 22 15:09:31 CET 2010


merge(t1,t2, by="a", all.x = TRUE)

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
  

> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org 
> [mailto:r-help-bounces op r-project.org] Namens Joel
> Verzonden: maandag 22 november 2010 15:07
> Aan: r-help op r-project.org
> Onderwerp: [R] Prob with merge
> 
> 
> Hi
> 
> Im trying to merge 2 data frames using merge but I dont get 
> the result i want
> 
> Lets make this a small test as my data set is to big to put 
> in here :).
> 
> t1<-data.frame(a=c(1,2,3,4,5,6),b=c(11,11,NA,11,11,11))
> t1<-data.frame(a=c(1,2,3,4,5,8),b=c(12,12,12,12,12,32))
> 
> this gives me:
> 
> > t1
>   a  b
> 1 1 12
> 2 2 12
> 3 3 12
> 4 4 12
> 5 5 12
> 6 8 32
> > t2
>   a  b
> 1 1 11
> 2 2 11
> 3 3 NA
> 4 4 11
> 5 5 11
> 6 6 11
> 
> now when i merge i get:
> > merge(t1,t2, by="a")
>   a b.x b.y
> 1 1  12  11
> 2 2  12  11
> 3 3  12  NA
> 4 4  12  11
> 5 5  12  11
> 
> 
> But what I want is it to look like:
> 
>    a b.x b.y
> 1 1 12 11
> 2 2 12 11
> 3 3 12 NA
> 4 4 12 11
> 5 5 12 11
> 6 8 32 NA
> 
> So I keep all of the rows from t1 and get an NA in dose slots 
> at the t2 part of the merge.
> Anyone know how to accomplice this?
> 
> Thx
> //Joel 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Prob-with-merge-tp3053652p3053652.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help op 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