Skip to content
Prev 306876 / 398506 Next

(no subject)

HI,

You mentioned what you don't want as output.? 


So, this might be a bit of guesswork.

Try this:
set1<-structure(list(ID = c("ds001", "ds001", "ds001", "ds001", "ds001", 
"ds001", "ds001", "ds001", "ds001", "ds001", "ds001", "ds001", 
"ds002", "ds002", "ds002", "ds002", "ds002", "ds002", "ds002"
), response = c("yes", "yes", "yes", "yes", "yes", "yes", "yes", 
"no", "no", "no", "no", "no", "yes", "yes", "yes", "yes", "no", 
"no", "no"), v1 = c(0.2, 0.3, 0.3, 0.4, 0.3, 0.3, 0.3, 0.3, 0.075, 
0.3, 0.3, 0.3, 0.3, 0.3, 0.83, 0.3, 0.3, 0.3, 0.3)), .Names = c("ID", 
"response", "v1"), class = "data.frame", row.names = c(NA, -19L
))


set2<-structure(list(ID = c("ds001", "ds001", "ds001", "ds001", "ds001", 
"ds001", "ds001", "ds001", "ds001", "ds002", "ds002", "ds002", 
"ds002", "ds002", "ds002", "ds002"), response = c("yes", "yes", 
"yes", "yes", "no", "no", "no", "no", "no", "yes", "yes", "yes", 
"yes", "no", "no", "no"), v1 = c(0.3, 0.2, 0.45, 0.6, 0.3, 0.3, 
0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3)), .Names = c("ID", 
"response", "v1"), class = "data.frame", row.names = c(NA, -16L
))


library(plyr)join(set1,set2,type="inner")

#But, there are a lot of duplicates in each set.? If you want to weed out the duplicates and then "combine" it:
? idx<-sapply(set1,function(x) !is.na(match(x,x[duplicated(x)])))
? idx1<-apply(idx,1,function(x) ifelse(all(x)==TRUE,TRUE,FALSE))
newset1<-data.frame(rbind(unique(set1[idx1,]),set1[!idx1,]))


#Similary for set2,
idx2<-duplicated(set2)|duplicated(set2,fromLast=TRUE)
newset2<-data.frame(rbind(unique(set2[idx2,]),set2[!idx2,]))
join(newset1,newset2,type="inner")
#Joining by: ID, response, v1
?# ?? ID response? v1
#1 ds001????? yes 0.3
#2 ds001?????? no 0.3
#3 ds002????? yes 0.3
#4 ds002?????? no 0.3
#5 ds001????? yes 0.2


A.K.






----- Original Message -----
From: John Kane <jrkrideau at inbox.com>
To: bibek sharma <mbhpathak at gmail.com>
Cc: r-help at r-project.org
Sent: Wednesday, October 3, 2012 1:51 PM
Subject: Re: [R] (no subject)

I have copied this to the R-help list. You only repied to me and it is much likelier that you will get help if it is posted to the list.? In relpying you should generally use reply all rather than reply in posting.

I still don't quite see what you are trying to get.? Most of the ID and reponse variables match.? Do you mean that you want common values in V1 and V2?? Again that seem strange.



I think you need to explain what the final output is likely to be and how you would expect to get it if you are doing this manually.

Thanks for supplying the code and the data. However next time please use dput() to provide the data. It supplies the data in an immediately useable manner.? For example I did dput(set1) and got:

structure(list(ID = c("ds001", "ds001", "ds001", "ds001", "ds001", 
"ds001", "ds001", "ds001", "ds001", "ds001", "ds001", "ds001", 
"ds002", "ds002", "ds002", "ds002", "ds002", "ds002", "ds002"
), response = c("yes", "yes", "yes", "yes", "yes", "yes", "yes", 
"no", "no", "no", "no", "no", "yes", "yes", "yes", "yes", "no", 
"no", "no"), v1 = c(0.2, 0.3, 0.3, 0.4, 0.3, 0.3, 0.3, 0.3, 0.075, 
0.3, 0.3, 0.3, 0.3, 0.3, 0.83, 0.3, 0.3, 0.3, 0.3)), .Names = c("ID", 
"response", "v1"), class = "data.frame", row.names = c(NA, -19L
))

Just add set1? <-? and you have an immediately useful 

John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails

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