Re: [R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
My apologize, it has been solved. Just include w inside of select, such as: select = c(w, x, y) On Fri, Oct 28, 2016 at 12:06 PM, lily li wrote: > 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 <- rowMea

[R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
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