I would like to calculate the mean of column x and y as below and add a column Mean,
> z
w x y
1 5 1 1
2 6 2 2
3 7 3 3
4 8 4 0
I am using the code like :
z$mean <- rowMeans(subset(z, select = c(x, y)), na.rm = TRUE)
but I don't know how to ignore the 0 in the last y value; the mean of that row for x and y values will be 4 only.
Output desired:
> z
w x y mean
1 5 1 1 1
2 6 2 2 2
3 7 3 3 3
4 8 4 0 4