s-news
[Top] [All Lists]

Re: Merging HLM datasets

To: "Roberts, J. Kyle" <jkrobert@bcm.tmc.edu>
Subject: Re: Merging HLM datasets
From: Chuck Cleland <ccleland@optonline.net>
Date: Tue, 13 Feb 2007 12:26:45 -0500
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <3FC0430478C30B4A9AF0AFF7863418F130F021@BCMEVS6.ad.bcm.edu>
References: <3FC0430478C30B4A9AF0AFF7863418F130F021@BCMEVS6.ad.bcm.edu>
User-agent: Thunderbird 1.5.0.9 (Windows/20061207)
Roberts, J. Kyle wrote:
> Dear All,
>  
> I have two datasets from HLM that I need to merge into a single dataset
> for use in S-PLUS/R.  Specifically, I need to take some teacher-level
> data (content knowledge) and apply it to every case for that teacher in
> the student-level dataset.  Any ideas?  I couldn't figure out how to do
> it using "merge."
>  
> I think that the answer to this is on the listserv, but I get a "Don't
> have permission" error when I try and search, so sorry for the repeat.

  I think this should be straight forward if you have a teacher ID
variable in both data frames.

teach <- data.frame(tid = 1:6, knowledge = runif(6))

student <- data.frame(sid = 1:20, tid = rep(1:5, each=4),
               grade = sample(c("A","B","C","D","F"), 20, replace=TRUE))

merge(teach, student, by="tid", all.x=FALSE, all.y=TRUE)
   tid knowledge sid grade
 1   1  0.646860   1     C
 2   1  0.646860   2     F
 3   1  0.646860   3     B
 4   1  0.646860   4     F
 5   2  0.666409   5     F
 6   2  0.666409   6     D
 7   2  0.666409   7     F
 8   2  0.666409   8     A
 9   3  0.842619   9     F
10   3  0.842619  10     C
11   3  0.842619  11     A
12   3  0.842619  12     D
13   4  0.647419  13     D
14   4  0.647419  14     F
15   4  0.647419  15     C
16   4  0.647419  16     B
17   5  0.746939  17     A
18   5  0.746939  18     C
19   5  0.746939  19     C
20   5  0.746939  20     F

hope it helps,

Chuck Cleland

> Thanks,
> Kyle
>  
> ***************************************
> J. Kyle Roberts, Ph.D.
> Baylor College of Medicine
> Center for Educational Outreach
> One Baylor Plaza, MS:  BCM411
> Houston, TX   77030-3411
> 713-798-6672 - 713-798-8201 Fax
> jkrobert@bcm.edu
> ***************************************

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

<Prev in Thread] Current Thread [Next in Thread>