value <- 1:10
Name <- c(rep("A",5),rep("B",5))
data <- data.frame(Name, value)
我使用聚合的方法是
> aggregate(factor(Name) ~ value, data=data, FUN="sum")
Error in Summary.factor(1L, na.rm = FALSE) :
sum not meaningful for factors
我在跟踪链接时遇到同样的错误
> data[] <- lapply(data, function(x) type.convert(as.character(x)))
> aggregate(Name ~ value, data, sum)
Error in Summary.factor(1L, na.rm = FALSE) :
sum not meaningful for factors
由于
答案 0 :(得分:3)
您必须切换Name
和value
:
aggregate(value ~ Name, data = data, FUN = "sum")
Name value
1 A 15
2 B 40