一意の列 ID が文字の場合、どのように集計を使用しますか?
aggregate(data, list(data$colID), sum)
Error in Summary.factor(c(1L, 1L), na.rm = FALSE) :
sum not meaningful for factors
キャラチェンジ..
data$colID<-as.character(data$colID)
aggregate(data, list(data$colID), sum)
Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument
ddply I get a similar error.
Error in FUN(X[[1L]], ...) :
only defined on a data frame with all numeric variables
colID で集計したいだけで、合計したくありません。他のすべての列を合計したい。
dput(data)
structure(list(colID = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("a",
"b"), class = "factor"), col1 = c(1, 0, 0, 0, 2), col2 = c(0,
1, 0, 2, 0), col3 = c(0, 0, 1, 0, 0), col4 = c(5, 5, 5, 7, 7)), .Names = c("colID",
"col1", "col2", "col3", "col4"), row.names = c(NA, -5L), class = "data.frame")