library(tidyverse)
df <- tibble(Date = as.Date(c("2020-01-01", "2020-01-02")),
Shop = c("Store A", "Store B"),
Employees = c(5, 10),
Sales = c(1000, 3000))
#> # A tibble: 2 x 4
#> Date Shop Employees Sales
#> <date> <chr> <dbl> <dbl>
#> 1 2020-01-01 Store A 5 1000
#> 2 2020-01-02 Store B 10 3000
我正在从 dplyr spread/gather 切换到 hub_* 以下dplyr 参考指南 https://tidyr.tidyverse.org/reference/pivot_longer.html。我想通过以下方式收集“员工”和“销售”列:
df %>% pivot_longer(-Date, -Shop, names_to = "Names", values_to = "Values")
#> Error in build_longer_spec(data, !!cols, names_to = names_to,
#> values_to = values_to, : object 'Shop' not found
但我收到这个错误。似乎我做的一切都是对的。但我显然不是。你知道出了什么问题吗?