Sorry, I didn’t formulate it in the message header. I hope my example will be clearer!
If I start with a data frame:
test.df <- data.frame(group=c(rep("a",4), rep("b",4)), var=rep(1:4,2), min= runif(8), q25=runif(8,1,2), q75=runif(8,2,3), max=runif(8,3,4)) head(test.df,2) group var min q25 q75 max 1 a 1 0.59078504 1.199138 2.119283 3.869486 2 a 2 0.06131107 1.676109 2.603068 3.739955
I know, it can melt it with id = c (group, var)
library(reshape2) head(melt(test.df, id=c("group", "var")),2) group var variable value 1 a 1 min 0.59078504 2 a 2 min 0.06131107
But what I'm looking for is a way to get the two value columns by pairing min-max and q25-q75 so that it looks like this:
group var variable value1 value2 1 a 1 min-max 0.59078504 3.869486 1 a 1 q25-q75 1.199138 2.119283 2 a 2 min-max 0.06131107 3.739955 2 a 2 q25-q75 1.676109 2.603068
I'm a bit stuck in melt / cast and can't pull myself out, I'm sure there must be a neat way to do this?
edit : this is a simplified example with two pairs of variables - the idea is to solve this for more pairs with minimal “manual” work.