如何在dplyr中正确使用pivot_longer

问题描述 投票:0回答:1

我目前正在使用pivot_longer中的简单函数。

这里是代码:

poll %>%
  pivot_longer(poll, c(`Basketball`,`Football`), names_to="Sport", values_to="Percentage")

这些是用于查找篮球和足球百分比的代码。

这里是错误消息:

错误:必须对具有有效下标向量的列进行子集设置。

任何人都可以看看我的代码有什么问题吗?

r dplyr pivot data-manipulation
1个回答
1
投票
poll %>% pivot_longer(c("Basketball","Football"), names_to="Sport", values_to="Percentage")
OR

pivot_longer(poll, c("Basketball","Football"), names_to="Sport", values_to="Percentage")

© www.soinside.com 2019 - 2024. All rights reserved.