Skip to content
Prev 306888 / 398506 Next

(no subject)

HI,

I guess I understand what you meant (read the very first post on the same subject).
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", "v2"), class = "data.frame", row.names = c(NA, -16L
))

?set1$id<-unlist(with(set1,tapply(set1[,2],set1[,1],seq)))
?set2$id<-unlist(with(set2,tapply(set2[,2],set2[,1],seq)))
combine<-subset(merge(set1,set2,by=c("ID","response","id"),all=TRUE),select=-id)
#or with join()

#subset(join(set1,set2,by=c("ID","response","id"),type="full"),select=-id)
head(combine)
#???? ID response??? v1? v2
#1 ds001?????? no??? NA 0.3
#2 ds001?????? no??? NA 0.3
#3 ds001?????? no??? NA 0.3
#4 ds001?????? no 0.300 0.3
#5 ds001?????? no 0.075 0.3
#6 ds001?????? no 0.300? NA
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.