You can also use the version of devel data.table ie v1.9.5 , which can take multiple measure columns.
We get the unique column names of the dataset that are not Day columns, and remove the part of the suffix that begins with . . Convert 'data.frame' to 'data.table' ( setDT(df1) ). Use melt and specify regex patterns in the measure argument. Other options include changing the column names "value" and "variable" ( value.name , variable.name ). By default, the Group column will be a numerical index that can be replaced with unique names from an earlier stage.
library(data.table)#v1.9.5+ nm1 <- unique(sub('\\..*', '', colnames(df1)[-1])) melt(setDT(df1), measure=patterns('Average$', 'SD$'), value.name=c('Average', 'SD'), variable.name='Group')[, Group:= nm1[Group]][] # Day Group Average SD # 1: 0.00000 HL 8760 2337.8440 # 2: 1.90625 HL 13300 1016.2910 # 3: 3.00000 HL 14500 2945.0980 # 4: 4.00000 HL 16200 1006.8930 # 5: 0.00000 D 8900 924.2742 # 6: 1.90625 D 11900 2308.2661 # 7: 3.00000 D 7320 1308.0389 # 8: 4.00000 D 9160 514.2177 # 9: 0.00000 LL 10000 1120.7850 #10: 1.90625 LL 12100 3581.7630 #11: 3.00000 LL 12300 4338.8970 #12: 4.00000 LL 15100 4362.2610 #13: 0.00000 noHKB 8030 1592.6460 #14: 1.90625 noHKB 3860 1031.0570 #15: 3.00000 noHKB 1750 1793.5830 #16: 4.00000 noHKB 2710 2691.6480
Installation instructions for the devel version: here
data
df1 <- structure(list(Day = c(0, 1.90625, 3, 4), HL.Average = c(8760L, 13300L, 14500L, 16200L), D.Average = c(8900L, 11900L, 7320L, 9160L), LL.Average = c(10000L, 12100L, 12300L, 15100L), noHKB.Average = c(8030L, 3860L, 1750L, 2710L), HL.SD = c(2337.844, 1016.291, 2945.098, 1006.893), D.SD = c(924.2742, 2308.2661, 1308.0389, 514.2177), LL.SD = c(1120.785, 3581.763, 4338.897, 4362.261), noHKB.SD = c(1592.646, 1031.057, 1793.583, 2691.648)), .Names = c("Day", "HL.Average", "D.Average", "LL.Average", "noHKB.Average", "HL.SD", "D.SD", "LL.SD", "noHKB.SD"), class = "data.frame", row.names = c(NA, -4L))