我正在尝试按列的每个唯一值聚合数据框:
A <- c(3, 5, 3, 5)
B <- c(10, 20, 30, 40)
C <- c(100, 200, 300, 400)
DF <- data.frame(A, B, C)
DF
Sort <- sort(unique(DF[[c("A")]]))
# 3 5
# I want to produce mean per column and per unique A column value
# A mean B mean C
# 3 20 200
# 5 30 300
我试过了 R: aggregate a data frame based on certain condition
aggregate(B~C, within(DF, A <- Sort), mean)
但我失败了。
有人可以帮助我吗?