[R] match in dependence of 2 columns

arun smartpink111 at yahoo.com
Thu Feb 14 19:40:04 CET 2013


HI,

If the dataset is similar to this:
dat1<- read.table(text=" 
                  cu.nr.         name              value  
A                 1                 Evo                 100 
B                 1                 Mer                 80  
C                 2                 Ford                50  
",sep="",header=TRUE,stringsAsFactors=F) 
dat2<- read.table(text=" 
                  cu.nr.         name      value2 value3        
A                 33                 Evo   60       120     
B                 1                 Mer    40        90 
C                 1                 Pold   20        30   
",sep="",header=TRUE,stringsAsFactors=F)  
library(plyr)
join(dat1,subset(dat2,select=c("cu.nr.","name")),by=c("cu.nr.","name"),type="right")
#  cu.nr. name value
#1     33  Evo    NA
#2      1  Mer    80
#3      1 Pold    NA
#or
join(dat1,dat2[,c("cu.nr.","name")],by=c("cu.nr.","name"),type="right")


A.K.



----- Original Message -----
From: Mat <matthias.weber at fnt.de>
To: r-help at r-project.org
Cc: 
Sent: Thursday, February 14, 2013 2:03 AM
Subject: Re: [R] match in dependence of 2 columns

thank you, this code works:

library(plyr)
join(dat1,dat2,by=c("cu.nr.","name"),type="right") 

but my dat2 frame has a lot of columns, which i don't want to match.
How can i say, that only the column "value" should be match to dat1 ?

Thank you.

Mat




--
View this message in context: http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405p4658508.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