I was trying to rearrange a dataframe using dataframe %>% pivot_longer( ) but would keep getting errors however I tried to specify the cols argument.
For instance, trying cols = (!colname) I'd get: Error: no applicable method for 'pivot_longer' applied to an object of class "logical" In addition: ‘!’ not meaningful for factors
Using starts_with("string") I'd get:
Error: starts_with()
must be used within a selecting function.
(Even though the example given on the help page for usage of 'starts_with()' gives "The cols argument of tidyr::pivot_longer()" as an example of where it should be used!)
And trying cols = c(2:18) gave me: no applicable method for 'pivot_longer' applied to an object of class "c('integer', 'numeric')
However, putting the name of the dataframe as the first argument within the brackets seems to have fixed the problem. I'm totally puzzled. I already tried library(tidyr) to check that no functions were being masked. Any idea what I could be doing wrong?