I have a date frame ("daten"), in which most columns are of numeric value. They typically range from 0 to 5. However, they can also take on the value 99. I want to calculate the mean of the columns, excluding only the values 99.
For example:
> mean(c(0, 1, 2, 3, 4, 5, 99))
[1] 16.28571
is not what I need, instead I want it to be calculated as if the vector was
> mean(c(0, 1, 2, 3, 4, 5))
[1] 2.5
, giving me the mean I am searching for.
There has been a similar question (Calculate mean, median by excluding any given number), but the solution does not work for me. I figured, however, that once I can exclude a certain value in any column, I can simply combine it with apply
, so I am actually looking for a way to calculate a mean for a certain vector, but ignoring certain values.