I have an R data frame like this with one factor variable, and two or more value variables.
> factorvar <- c('a', 'b', 'c')
> valvar1 <- c(1, 1, 1)
> valvar2 <- c(2, 2, 2)
> df <- data.frame(factorvar, valvar1, valvar2)
> df
factorvar valvar1 valvar2
1 a 1 2
2 b 1 2
3 c 1 2
I want to widen it such that the final data frame looks something like the following:
> dfnew
valvar1.a valvar1.b valvar1.c valvar2.a valvar2.b valvar2.c
1 1 1 1 2 2 2
dplyr/tidyr with spread only allow me to do it for one column (value).