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
-----Original Message-----
From: mbhpathak at gmail.com
Sent: Tue, 2 Oct 2012 09:27:57 -0700
To: jrkrideau at inbox.com
Subject: Re: [R] (no subject)
Hello John,
Here is the code, data set and resutls that I got. I want to combine
two data ( set1 and set2) in such a way that it only take common
values by id and response between these two sets. The output (data
combine) is not what I wanted.
Much appreciated any suggestion.
1library(car)
library(rgr)
library(nlme)
set1<-read.table("U:\\Longitudinal Study\\data1.txt",header=T)
set2<-read.table("U:\\Longitudinal Study\\data2.txt",header=T)
combine<-merge(set1,set2, by=c("ID","response"))
set1
ID response v1
1 ds001 yes 0.200
2 ds001 yes 0.300
3 ds001 yes 0.300
4 ds001 yes 0.400
5 ds001 yes 0.300
6 ds001 yes 0.300
7 ds001 yes 0.300
8 ds001 no 0.300
9 ds001 no 0.075
10 ds001 no 0.300
11 ds001 no 0.300
12 ds001 no 0.300
13 ds002 yes 0.300
14 ds002 yes 0.300
15 ds002 yes 0.830
16 ds002 yes 0.300
17 ds002 no 0.300
18 ds002 no 0.300
19 ds002 no 0.300
set2
ID response v2
1 ds001 yes 0.30
2 ds001 yes 0.20
3 ds001 yes 0.45
4 ds001 yes 0.60
5 ds001 no 0.30
6 ds001 no 0.30
7 ds001 no 0.30
8 ds001 no 0.30
9 ds001 no 0.30
10 ds002 yes 0.30
11 ds002 yes 0.30
12 ds002 yes 0.30
13 ds002 yes 0.30
14 ds002 no 0.30
15 ds002 no 0.30
16 ds002 no 0.30
On Tue, Oct 2, 2012 at 6:25 AM, John Kane <jrkrideau at inbox.com> wrote:
It's hard to know what's wrong since you did not supply your code.
Please supply a small working example and some data. To supply data use
the dput()
function, see ?dput() for details.
Welcome to R.
John Kane
Kingston ON Canada
-----Original Message-----
From: mbhpathak at gmail.com
Sent: Mon, 1 Oct 2012 14:25:20 -0700
To: r-help at r-project.org
Subject: [R] (no subject)
Hello,
I am a new R -user and request your help for the following problem.
I need to merge two dataset of longitudinal study which has two column
(id and respose) common. when I used merge option to join the datas
side be side, because of the repeated subject id, I got larger data
set which is not accurate.
I would like to connect twi data sets by id and response in such a
way that data are connected by same id and response type and if the
same subject has less data point in one data set, then produce NA.
Sample data sets is attached.
Bibek
____________________________________________________________
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
____________________________________________________________
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