r - colMeans with condition based on one of the column -
newbie here.
so have matrix dimension of 3*24. trying find mean of 3rd column if value of 2nd column in greater/lower x. values numeric.
what have been trying follow:
over40<-trainexer11$age>=40 below40<-trainexer11$age<40 the idea create logical variable each age group
colmeans(trainexer11, below40=true) then find mean of both variable if fulfils previous logical.
the code returned error (obviously) since not familiar r yet, don't know how 1 should proceed
we can use aggregate
aggregate(trainexer11~ agegrp, transform(df1, agegrp = age >=40), fun = mean)
Comments
Post a Comment