Thank you dear friends.  You have cleared my first doubt.  

My second doubt:
I have the same data sets "Elder" and "Younger". Elder <- data.frame(
  ID=c("ID1","ID2","ID3"),
  age=c(38,35,31))
Younger <- data.frame(
  ID=c("ID4","ID5","ID3"),
  age=c(29,21,"NA"))


 Row ID3 comes in both data set. It has a value (31) in "Elder" while "NA" in 
"Younger".

I need output like this.

ID    age
ID1  38
ID2  35
ID3  31
ID4  29
ID5  21 

Kindly help me.



On Thursday, 16 January 2014 9:16 PM, Marc Schwartz-3 [via R] 
<ml-node+s789695n4683682...@n4.nabble.com> wrote:
 
Not quite: 

> rbind(Elder, Younger) 
   ID age 
1 ID1  38 
2 ID2  35 
3 ID3  31 
4 ID4  29 
5 ID5  21 
6 ID3  31 

Note that ID3 is duplicated. 


Should be: 

> merge(Elder, Younger, by = c("ID", "age"), all = TRUE) 
   ID age 
1 ID1  38 
2 ID2  35 
3 ID3  31 
4 ID4  29 
5 ID5  21 


He wants to do a join on both "ID" and "age" to avoid duplications of rows when 
the same ID and age occur in both data frames. If the same column names (eg 
"Var") appears in both data frames and are not part of the 'by' argument, you 
end up with Var.x and Var.y in the result. 

In the case of two occurrences of the same ID but two different ages, if that 
is possible, both rows would be added to the result using the above code. 

Regards, 

Marc Schwartz 


On Jan 16, 2014, at 9:04 AM, Frede Aakmann Tøgersen <[hidden email]> wrote: 

________________________________

______________________________________________ 
[hidden email] 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. 




________________________________

If you reply to this email, your message will be added to the discussion below: 
http://r.789695.n4.nabble.com/Doubt-in-simple-merge-tp4683671p4683682.html 
To start a new topic under R help, email ml-node+s789695n78969...@n4.nabble.com 
To unsubscribe from R help, click here.
NAML



--
View this message in context: 
http://r.789695.n4.nabble.com/Doubt-in-simple-merge-tp4683671p4683718.html
Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to