Aggregate by NA in R

后端 未结 5 1973
闹比i
闹比i 2021-01-13 11:22

Does anybody know how to aggregate by NA in R.

If you take the example below

a <- matrix(1,5,2)
a[1:2,2] <- NA
a[3:5,2] <- 2
aggregate(a[,1]         


        
5条回答
  •  轮回少年
    2021-01-13 11:58

    Use summarize from dplyr

    library(dplyr)
    
    a %>%
      as.data.frame %>%
      group_by(V2) %>%
      summarize(V1_sum = sum(V1))
    

提交回复
热议问题