0

Newbie here.

So I have matrix with dimension of 3*24. I am trying to find a mean of 3rd column if the value of 2nd column in greater/lower than x. All the values are numeric.

What I have been trying to do is as follow:

over40<-TrainExer11$Age>=40
below40<-TrainExer11$Age<40

The idea is to create another logical variable for each age group

colMeans(TrainExer11, below40=TRUE)

Then to find the mean of both variable only IF it fulfils the previous logical.

The code returned an error (obviously) but since I am not very familiar with R yet, I don't know how one should proceed

  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Sep 11 '17 at 06:34

1 Answers1

0

We can use aggregate

aggregate(TrainExer11~ AgeGrp, transform(df1, AgeGrp = Age >=40), FUN = mean)
akrun
  • 874,273
  • 37
  • 540
  • 662