aggregate methods treat missing values (NA) differently

前端 未结 2 1492
孤城傲影
孤城傲影 2020-11-27 19:11

Here\'s a simple data frame with a missing value:

M = data.frame( Name = c(\'name\', \'name\'), Col1 = c(NA, 1) , Col2 = c(1, 1))
#   Name Col1 Col2
# 1 name          


        
2条回答
  •  臣服心动
    2020-11-27 19:46

    If you want the formula version to be equivalent try this:

    M = data.frame( Name = rep('name',5), Col1 = c(NA,rep(1,4)) , Col2 = rep(1,5))
    aggregate(. ~ Name, M, function(x) sum(x, na.rm=TRUE), na.action = na.pass)
    

提交回复
热议问题