sum non NA elements only, but if all NA then return NA

前端 未结 2 514
时光说笑
时光说笑 2021-01-12 05:25

I think I already got really good answers on the comments, but I will rephrase the question for future reference.

I am trying to sum by groups using data.table. The

2条回答
  •  余生分开走
    2021-01-12 06:15

    Using sum_ from hablar

    library(hablar)
    A[, as.numeric(sum_(col2)), .(col1)]
    #   col1 V1
    #1:    A NA
    #2:    B  5
    #3:    C  4
    

提交回复
热议问题