【发布时间】:2022-01-22 19:45:51
【问题描述】:
我想将我的数据总结为只有三列,如下所示:
col_1 = name of the country,
col_2 = percentage of 0s,
col_3 = percentage of 1s,
这是数据:
country = rep(c("USA", "UK", "AUS", "ARM", "BEL", "BRA", "CHN", "EGY", "FIN", "FRA"),
times = c(10, 5, 15, 10, 10, 10, 5, 15, 10, 10))
score= sample(c(0,1), replace=F)
dat = data.frame(country, score)
非常感谢。
【问题讨论】:
-
aggregate(score ~ country, dat, FUN = \(x) c(zero = 1 - mean(x), one = mean(x)))
标签: r