How to install pivot_long() and pivot_wide() in R

半世苍凉 提交于 2020-06-27 13:06:12

问题


If you want to try these new functions (pivot_wide and pivot long), you need to install the development version of tidyr:

devtools::install_github("tidyverse/tidyr").

But I have not managed to achieved it. I install a list of libraries except one, ( vctrs) and I don't know if that's the problem.

When I run the next code:

  mtcars_wide1 <- mtcars %>%
  pivot_wide(names_from = "am",
             values_from = "mpg")

R couldn't find the function.

enter image description here

Can you recommend me something?


回答1:


You probably don't have the lasted version of R installed - the latest is currently 3.6.1.

R.version

I had the same problem as you, but I updated R, reinstalled the dev version of the tidyverse

install.packages("devtools")
devtools::install_github("hadley/tidyverse")

…and all was good. Hope it works for you too!




回答2:


It seems they changed their names to pivot_wider and pivot_longer:

https://github.com/tidyverse/tidyr/issues/579




回答3:


pivot_longer() is from the package tidyr, so make sure it's installed and loaded:

install.packages("tidyr")
library(tidyr)


来源:https://stackoverflow.com/questions/56534005/how-to-install-pivot-long-and-pivot-wide-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!