0
relig_income_tidy <-   relig_income %>% 
pivot_longer(-religion, names_to = "income", values_to = "count")
glimpse(relig_income_tidy)

This is the 'tutorial' dataset that is given in the help section. It works, but when I try to apply the same code to my own dataset:

blackamoor2k19_tidy <- blackamoor2k19 %>% 
pivot_longer(-LIST, -Waypoint -Site, -Recorder, -Date, -Time, -Route, -VisitNumber, names_to = "Species", values_to = "count")

It does not work, resulting in the following error:

Error in build_longer_spec(data, !!cols, names_to = names_to, values_to = values_to,  : 
  object 'Waypoint' not found 

The dataset has the columns I've mentioned in my line of code, as well as additional columns of various bird species which I want to convert to rows. I've tried a few things but I can't seem to figure it out.

Thanks!

Kodewings
  • 29
  • 7

1 Answers1

0

You need to wrap your column selections with c, this should work:

blackamoor2k19_tidy <- blackamoor2k19 %>% 
    pivot_longer(c(-LIST, -Waypoint, -Site, -Recorder, -Date, -Time, -Route, -VisitNumber), 
    names_to = "Species", values_to = "count")
dave-edison
  • 3,666
  • 7
  • 19