循环通过列创建总结
我想循环遍历DF的列,并使用summarize()函数提取人,min和max的摘要。
到目前为止,我创建了以下内容,其中所有我想要的列表都在分配给vars的列表()中捕获。
vars <- list("npl_lnratio", "l_npl_lnratio", "llp_loans", "llp_npl", "eta", "cap",
"roaa", "roae", "lta", "ltd", "efficiency", "cta", "g", "unemp", "inf", "hpi", "debt")
for (i in vars) {
df5 %>%
group_by(i) %>%
count() %>%
ungroup() %>%
summarize(mean(n), min(n), max(n))
}
运行此作品会导致以下错误:
Error: Must group by variables found in `.data`.
* Column `i` is not found.
如何创建一个for循环,该循环确实提供了vars列表中所有列的摘要?
I want to loop through the columns of the df and extract a summary of the man, min, and max using the summarise() function.
So far, I've created the following, where all the columns of which I'd like a summary are captured in a list() assigned to vars.
vars <- list("npl_lnratio", "l_npl_lnratio", "llp_loans", "llp_npl", "eta", "cap",
"roaa", "roae", "lta", "ltd", "efficiency", "cta", "g", "unemp", "inf", "hpi", "debt")
for (i in vars) {
df5 %>%
group_by(i) %>%
count() %>%
ungroup() %>%
summarize(mean(n), min(n), max(n))
}
Running this piece leads to the following error:
Error: Must group by variables found in `.data`.
* Column `i` is not found.
How can I create a for loop which does provide summaries of all the columns in the vars list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
group_by仅采用未引用的变量。一种解决方法是以下内容。
group_by only takes unquoted variables. One way to go around that would be the following.