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

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -