Hello,
in a dataset I have got a bunch of numeric variables that I have to calculate the arithmetic mean on, but only if other variables take a certain value. E.g. x, y should be averaged only if x_1=1, y_1=2. If the if-condition is not fufilled for a certain variable this variable should not contribute to the mean (see example below)
x x_1 y y_1 mean
4 1 5 2 4.5
3 2 2 2 2
7 1 6 1 7
3 4 4 5 .
Is there an easy way to code such a task? Thanks a lot for your hints in advance.
Kind regards,
Michael
in a dataset I have got a bunch of numeric variables that I have to calculate the arithmetic mean on, but only if other variables take a certain value. E.g. x, y should be averaged only if x_1=1, y_1=2. If the if-condition is not fufilled for a certain variable this variable should not contribute to the mean (see example below)
x x_1 y y_1 mean
4 1 5 2 4.5
3 2 2 2 2
7 1 6 1 7
3 4 4 5 .
Is there an easy way to code such a task? Thanks a lot for your hints in advance.
Kind regards,
Michael
Comment