Calculating the mean of specific people in a dataframe

Hello everybody,

I got a little question. I have to submit my R-script until Monday and I'm struggling with one task.

I have a Dataframe called my.matrix

my.matrix <- cbind(id, sex, weight, height)

The task is as follows: "Calculate the mean of weight of all participants with an odd id"
Is there a function to calculate the mean of weight of all participants with an odd id with the basic r studio functions?

Thank you in advance

Hello,

you can just use the modulo operation (%%) on your IDs to create a subset of your data. You could improve it by using a data.frame instead of a matrix build with cbind() and making use of the native pipe |>.

Kind regards

Thank you very much!!

I just needed to know about the modulo operation. :grin:

Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.