[R] ave and sd

Patrick Hausmann c18g at uni-bremen.de
Wed Nov 21 10:45:55 CET 2007


Dear list,

I'm still trying to calculate the sd for V2 for
each group in V1 if V3 is '0':

> x
    V1   V2 V3
1 A01 2.40  0
2 A01 3.40  1
3 A01 2.80  0
4 A02 3.20  0
5 A02 4.20  0
6 A03 2.98  1
7 A03 2.31  0
8 A04 4.20  0

# Work
x$vmean <- ave(x$V2, x$V1, x$V3 == 0, FUN = mean)

# Work
x$vsd2 <- ave(x$V2, x$V1, FUN = sd)

# Doesn't work
x$vsd <- ave(x$V2, x$V1, x$V3 == 0, FUN = sd)

Thank you for any help!

Patrick



More information about the R-help mailing list