Hi,
Hope this is what you meant..
with(dat1,mean(V21[(V2==1|V2==0) & V24<25],na.rm=TRUE))?
#[1] 2.8125
?sapply(0:1,function(i) with(dat1,mean(V21[V2==i & V24<25],na.rm=TRUE)))
#[1] 2.75 3.00
"..... who are in condition 1 or 0 (V2) and then vice
versa ..."
?dat1[,21]
# [1]?? NA 3.40 3.00 3.00?? NA 3.00 2.75 2.50 3.30 4.00
?with(dat1,(V21==1|V21==0) & V24<25) #here the condition is not clear..
# [1]??? NA FALSE FALSE FALSE??? NA FALSE FALSE FALSE FALSE FALSE
?with(dat1,mean(V2[(V21==1|V21==0) & V24<25],na.rm=TRUE))
#[1] NaN
A.K.
Hi.
Thanks for the quick reply. ?
To clarify, I'm interested in V21 (which is GPA) but I want to
look at it for people who are in condition 1 or 0 (V2) and then vice
versa, furthermore, I want to further filter for it to be people who are
under 25 (V24). ?So to sum up, I want to see what the GPA is for people
in condition 1 who are under 25. ?Hope this makes sense.
The data set is actually 158 rows with 25 columns for now, and will include 300+
more participants. ? ?
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Sunday, August 25, 2013 9:20 PM
Subject: Re: Sorting data
Hi,
It's not clear what you really wanted.? May be this helps:
dat1<- read.table(text="
? V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20?? V21
V22 V23 V24 V25 V26
1???? 1? 1? 3? 1 NA NA? 1 NA NA?? 1?? 2?? 7?? 5?? 3?? 2 1.0? 15? 17?? 5?? 1???
NA?? 1?? 2? 19?? 1?? 1
2???? 2? 0? 1? 1 NA NA? 1 NA NA?? 1? NA? NA?? 5? NA? NA 3.0? NA? NA?? 3?? 5
3.400?? 1?? 2? 39?? 1?? 1
3???? 3? 1? 2? 2 NA NA? 2 NA NA?? 2?? 1? NA?? 5?? 5? NA 2.0?? 3? NA?? 5? NA
3.000?? 2?? 5? 19?? 1?? 3
4???? 4? 0? 1? 1 NA NA? 1 NA NA?? 1? NA? NA?? 5? NA? NA 2.0? NA? NA?? 5? NA
3.000?? 2?? 2? 17?? 1?? 2
5???? 5? 1? 2? 9 NA NA? 1 NA NA?? 1?? 9? NA?? 5?? 3? NA 3.0?? 3? NA?? 4? NA???
NA?? 1?? 6? 17?? 1?? 1
6???? 6? 1? 2? 1 NA NA? 1 NA NA?? 1? 10? NA?? 5?? 3? NA 3.0?? 5? NA?? 4? NA
3.000?? 1?? 8? 32?? 1?? 1
7???? 7? 0? 1? 1 NA NA? 1 NA NA?? 1? NA? NA?? 5? NA? NA 2.0? NA? NA?? 3?? 1
2.750?? 1?? 9? 20?? 1?? 1
8???? 8? 0? 1? 1 NA NA? 1 NA NA?? 1? NA? NA?? 5? NA? NA 2.0? NA? NA?? 4?? 4
2.500?? 1?? 2? 21?? 1?? 1
9???? 9? 0? 2? 1 NA NA? 1 NA NA?? 1?? 2? NA?? 5?? 2? NA 3.0? NA? NA?? 4?? 2
3.300?? 1?? 2? 29?? 1?? 1
10?? 10? 0? 1? 1 NA NA? 1 NA NA?? 1? NA? NA?? 5? NA? NA 2.0? NA? NA?? 4? NA
4.000?? 2?? 2? 28?? 2?? 2
",sep="",header=TRUE)
with(dat1,mean(V21[(V2==1) & V24>25],na.rm=TRUE))
#[1] 3
A.K.
I'm trying to sort data depending on multiple variables. ?For example, I
want to get V21 mean based on V2 = 1 (condition) and V24 >25
(age). ?
? ?V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 ? V21
V22 V23 V24 V25 V26
1 ? ? 1 ?1 ?3 ?1 NA NA ?1 NA NA ? 1 ? 2 ? 7 ? 5 ? 3 ? 2 1.0 ?15 ?17 ? 5 ? 1 ?
?NA ? 1 ? 2 ?19 ? 1 ? 1
2 ? ? 2 ?0 ?1 ?1 NA NA ?1 NA NA ? 1 ?NA ?NA ? 5 ?NA ?NA 3.0 ?NA ?NA ? 3 ? 5
3.400 ? 1 ? 2 ?39 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