I have the following dummy data:
library(dplyr) library(tidyr) library(reshape2) dt <- expand.grid(Year = 1990:2014, Product=LETTERS[1:8], Country = paste0(LETTERS, "I")) %>% select(Product, Country, Year) dt$value <- rnorm(nrow(dt))
I choose two product combinations:
sdt <- dt %>% filter((Product == "A" & Country == "AI") | (Product == "B" & Country =="EI"))
and I want to see the values next to each other for each combination. I can do this with dcast :
sdt %>% dcast(Year ~ Product + Country)
Is it possible to do this using spread from the tidyr package?
r tidyr reshape2
mpiktas Jul 24 '14 at 9:27 2014-07-24 09:27
source share