Hi R users, I have the dataframe as below:
w=c(5,6,7,8) x=c(1,2,3,4) y=c(1,2,3) length(y)=4 z=data.frame(w,x,y) z$mean1 <- rowMeans(subset(z, select = c(x, y)), na.rm = T) z$mean2 <- rowMeans(subset(z, select = c(x, y)), na.rm=F) w x y mean1 mean2 1 5 1 1 1 1 2 6 2 2 2 2 3 7 3 3 3 3 4 8 4 NA 4 NA How to calculate mean value for the three columns, while default removing NAs. For example, for the fourth row, the mean value should be (8+4)/2 = 6 Thanks for your help. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.