On 05/08/07, sigalit mangut-leiba <smangut at gmail.com>
wrote:> Hi all,
> i'm trying to run a two-sample t-test.
> i have a longitudinal data that looks like this:
> idn age class
> 1 22 1
> 1 22 1
> 1 22 1
> 1 22 1
> 2 63 3
> 2 63 3
> 2 63 3
> 3 43 2
> 3 43 2
> 3 43 2
> 3 43 2
> 3 43 2
> 3 43 2
> 4 37 1
> 4 37 1
> 4 37 1
> .
> .
> .
> i want to compare between class 1 and 3, to see if there are any age
> differences, and want to count every id once (not all id numbers have the
> same number of rows).
> i tried:
>
> with(
>
> subset(x1, !duplicated(idn)),
>
> t.test(age[class=="1"],age[hidclass=="3"]
>
> )
>
> but it didn't work. any suggestions?
>
If you had given us the error message that you (presumably) had
received, then the solution is much easier:
You use the code:
age[hidclass=="3"]
Did you try running this before expected t.test() to function on it?
Try going through this:
# it is always best to generate some test data
# often doing this will illustrate the best way of doing things!
d1 <- data.frame(idn =sort(rep(1:100,each=4)),
age = rep(round(rnorm(100, mean=50, sd=15)), each=4),
class =rep(round(rnorm(100, mean=3, sd=1)), each=4))
# exclude duplicated
d1.s <- d1[!duplicated(d1$id),]
t.test(d1.s[class==3,], d1.s[class==1,])
Mark
--
Dr. Mark Wardle
Clinical research fellow and specialist registrar, Neurology
Cardiff, UK