Converting between long and short data.frame formats
Converting between long and short data.frame formats Simple (?) tidyr question: tidyr I have a data.frame which has several grouping columns and several value columns, in long format. I want to convert it to short (wide) format, where the key would be one of the grouping columns and the resulting data.frame would have a column for each combination of all the other grouping columns and each of the value columns. data.frame key data.frame Here's my long-format data.frame : data.frame set.seed(1) library(dplyr) df <- data.frame(treatment = rep(c(rep("T1",3),rep("T2",3)),2), species = c(rep("S1",6),rep("S2",6)), group = rep(LETTERS[1:3],4), n = as.integer(runif(12,10,20))) %>% dplyr::group_by(treatment,species) %>% dplyr::mutate(freq = n/sum(n)) And here's what I want the resulting wide-format data.frame to be: data.frame res.df <- data.frame(group = LETTERS[1:3], ...