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
>> combine
> ID response v1 v2
> 1 ds001 no 0.300 0.30
> 2 ds001 no 0.300 0.30
> 3 ds001 no 0.300 0.30
> 4 ds001 no 0.300 0.30
> 5 ds001 no 0.300 0.30
> 6 ds001 no 0.075 0.30
> 7 ds001 no 0.075 0.30
> 8 ds001 no 0.075 0.30
> 9 ds001 no 0.075 0.30
> 10 ds001 no 0.075 0.30
> 11 ds001 no 0.300 0.30
> 12 ds001 no 0.300 0.30
> 13 ds001 no 0.300 0.30
> 14 ds001 no 0.300 0.30
> 15 ds001 no 0.300 0.30
> 16 ds001 no 0.300 0.30
> 17 ds001 no 0.300 0.30
> 18 ds001 no 0.300 0.30
> 19 ds001 no 0.300 0.30
> 20 ds001 no 0.300 0.30
> 21 ds001 no 0.300 0.30
> 22 ds001 no 0.300 0.30
> 23 ds001 no 0.300 0.30
> 24 ds001 no 0.300 0.30
> 25 ds001 no 0.300 0.30
> 26 ds001 yes 0.200 0.30
> 27 ds001 yes 0.200 0.20
> 28 ds001 yes 0.200 0.45
> 29 ds001 yes 0.200 0.60
> 30 ds001 yes 0.300 0.30
> 31 ds001 yes 0.300 0.20
> 32 ds001 yes 0.300 0.45
> 33 ds001 yes 0.300 0.60
> 34 ds001 yes 0.300 0.30
> 35 ds001 yes 0.300 0.20
> 36 ds001 yes 0.300 0.45
> 37 ds001 yes 0.300 0.60
> 38 ds001 yes 0.400 0.30
> 39 ds001 yes 0.400 0.20
> 40 ds001 yes 0.400 0.45
> 41 ds001 yes 0.400 0.60
> 42 ds001 yes 0.300 0.30
> 43 ds001 yes 0.300 0.20
> 44 ds001 yes 0.300 0.45
> 45 ds001 yes 0.300 0.60
> 46 ds001 yes 0.300 0.30
> 47 ds001 yes 0.300 0.20
> 48 ds001 yes 0.300 0.45
> 49 ds001 yes 0.300 0.60
> 50 ds001 yes 0.300 0.30
> 51 ds001 yes 0.300 0.20
> 52 ds001 yes 0.300 0.45
> 53 ds001 yes 0.300 0.60
> 54 ds002 no 0.300 0.30
> 55 ds002 no 0.300 0.30
> 56 ds002 no 0.300 0.30
> 57 ds002 no 0.300 0.30
> 58 ds002 no 0.300 0.30
> 59 ds002 no 0.300 0.30
> 60 ds002 no 0.300 0.30
> 61 ds002 no 0.300 0.30
> 62 ds002 no 0.300 0.30
> 63 ds002 yes 0.300 0.30
> 64 ds002 yes 0.300 0.30
> 65 ds002 yes 0.300 0.30
> 66 ds002 yes 0.300 0.30
> 67 ds002 yes 0.300 0.30
> 68 ds002 yes 0.300 0.30
> 69 ds002 yes 0.300 0.30
> 70 ds002 yes 0.300 0.30
> 71 ds002 yes 0.830 0.30
> 72 ds002 yes 0.830 0.30
> 73 ds002 yes 0.830 0.30
> 74 ds002 yes 0.830 0.30
> 75 ds002 yes 0.300 0.30
> 76 ds002 yes 0.300 0.30
> 77 ds002 yes 0.300 0.30
> 78 ds002 yes 0.300 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
>>> ______________________________________________
>>> 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.
>>
>> ____________________________________________________________
>> 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