You can convert your dataframe to long format with grouped columns in one step using reshape(...)
. Assuming your dataframe is df
:
gg <- reshape(df,idvar="hrc_id", # idvar: identifies cases
times=c("confidence","quality"), # group of columns to be reshaped
timevar="measurement", # column name to use for grouping vars
varying=2:5, # columns are to be reshaped
v.names=c("value","value.ci"), # column names for reshaped values
direction="long") # convert to long format
gg
# hrc_id measurement value value.ci
# 0.confidence 0 confidence 3.573718 0.02068321
# 1.confidence 1 confidence 3.403846 0.03193104
# 10.confidence 10 confidence 3.160256 0.02520483
# 0.quality 0 quality 4.576923 0.02864818
# 1.quality 1 quality 1.658120 0.04441434
# 10.quality 10 quality 3.038462 0.04476492
As far as I know you cannot do this with melt(...)
- you'd have to use the rbind
approach mentioned in your comment.