【发布时间】:2021-12-29 05:51:00
【问题描述】:
我正在尝试将 for 循环转换为基于 c("country", "continent") 的组摘要统计功能。任何帮助将不胜感激,非常感谢。
library(gapminder)
library(purr)
cont <- unique(gapminder$continent)
df <- NULL
temp <- NULL
for(i in 1:(length(cont))) {
temp <- gapminder[gapminder$continent == cont[i], ]
#df[[i]] <- temp
df[[i]] <- temp %>% split(.$continent) %>% map(summary)
}
df
预期的答案
my.function(gapminder, c("country", "continent"))
【问题讨论】:
-
你的 for 循环正确吗?它没有提到国家
标签: r function for-loop data-manipulation