Element-wise mean in R

前端 未结 3 949
感情败类
感情败类 2020-12-10 23:42

In R, I have two vectors:

a <- c(1, 2, 3, 4)
b <- c(NA, 6, 7, 8)

How do I find the element-wise mean of the two vectors, removing NA,

3条回答
  •  伪装坚强ぢ
    2020-12-11 00:42

    I'm not exactly sure what you are asking for, but does

    apply(rbind(a,b),2,mean,na.rm = TRUE)
    

    do what you want?

提交回复
热议问题