Your gather
line should look like:
dat %>% gather(variable, date, -teacher, -pd)
This says “Gather all variables except teacher
and pd
, calling the new key column ‘variable’ and the new value column ‘date’.”
As an explanation, note the following from the help(gather)
page:
...: Specification of columns to gather. Use bare variable names.
Select all variables between x and z with ‘x:z’, exclude y
with ‘-y’. For more options, see the select documentation.
Since this is an ellipsis, the specification of columns to gather is given as separate (bare name) arguments. We wish to gather all columns except teacher
and pd
, so we use -
.