I have a long format dataframe dogs that I\'m trying to reformat to wide using the reshape() function. It currently looks like so:
dogid month year traini
You can do the same thing using the new replacement for reshape2, tidyr:
library(tidyr)
library(dplyr)
data %>% unite(newcol, c(year, month, trainingtype)) %>%
spread(newcol, timeincomp)
dogid home school 2014_1_1 2014_2_1 2015_12_2
1 12345 1 1 340 360 NA
2 31323 7 3 500 520 440
First, we unite the year, month and trainingtype columns into a new column called newcol, then we spread the data with timeincomp as our value variable.
The NA is there as we have no value, you can give it one by changing fill = NA in the spread function.