Trying to go from long to wide on a dataframe with multiple variables. The data represent evaluation outcomes. There's an ID (for the case), date of eval, eval core, eval reader, then a series of 8 characteristics with values of 1 or 0 (yes or no).
A truncated picture of the head(df) is below
# A tibble: 6 x 8 id datetime eval reader rigor learn <chr> <dttm> <chr> <chr> <dbl> <dbl> 10001 2017-01-23 11:08:38 No CM 0 0 10001 2016-11-26 07:15:58 No CL 0 0 10002 2017-02-04 14:03:17 No SM 1 0 10002 2016-11-26 14:04:48 No LM 1 1 10003 2016-11-27 11:05:11 No AH 0 0 10003 2017-02-01 08:35:08 No NT 0 0
(plus 6 more characteristics not shown)
I'd like to turn it long to wide so that each ID is it's own line and time, reader, eval and characteristics each have their own column with a 1 or 2 (for 1st and 2nd evals).
I'm migrating my work from SAS to r...this is something I've done a ton of times in SAS but new to this level of data wrangling in r.
I tried spread with this code:
evaldf2 <- spread(evaldf, id, datetime, eval, reader, rigor, learn, leadership, persist)
and got this error:
Error in spread(read17reprex, cpid, form_datetime, form_evaluation, form_reader, : unused arguments (leadership, persist)
Then tried reshape on the entire set:
evaldf2 <- reshape(evaldf, idvar = "id", direction = "wide")
Which threw back this error:
Error: Column `time` not found
Not sure what I'm missing here. Instead of going wide should I create a eval sequence number...1 and 2 for 1st and 2nd eval...so I can do my calculations (characteristics by eval, reader, etc...) based on read number?