Sorry I'm not particularly articulate in the post title..I hope my example will be clearer!
If I start out 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 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 two "value" columns by pairing min-max and q25-q75 so that it looks like:
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 got a bit stuck on melt/cast and cant pull myself out, I'm sure there must be a neat way to accomplish this?
edit: this is a simplified example with only two pairs of variables - the idea is to solve this for larger numbers of pairs with minimal 'manual' work.