[R] intersect of 2 data frames

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun May 6 21:57:31 CEST 2007


Dimitris Rizopoulos wrote:
> look at ?merge(), e.g., try something like the following:
>
> merge(pretestm, posttest, by = "StuNum")
>
> check also the on-line help page for more info, especially for the  
> 'all' argument.
>
>   
Or, to follow the original line of reasoning:

subset(pretest, StuNum %in% common.id)

(This doesn't scale well to large sizes of common.id, but neither did 
the SQL statement...)
>   
>> Greetings!
>>
>> I am a new user of R.  The only one in my department, all others use SPSS.
>>
>> I have two data sets of students with test scores, pretest and
>> posttest.  The first column StuNum and then columns of scores.
>>
>> The problem is that the lists are slightly different not all students
>> are in both data sets.
>>
>> So I did:
>>
>> intersect(pretest$StuNum, posttest$StuNum) -> common.id
>>
>> At this point I need to select from pretest the students in common.id
>> and do the same with posttest.
>>
>> I have tried several things but, basically I do not know how to do so.
>>
>> In SQL it should be something like:
>>
>> select pretest$StuNum in common.id
>>
>>
>> Any pointers?
>>
>> Thanks,
>> Enrico
>>
>>
>> --
>> Enrico Indiogine
>>
>> Mathematics Education
>> Texas A&M University
>> hindiogine at gmail.com
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>>
>>
>>     
>
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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