i want to add an extra column samples in the melted data.table which will be keys for columns D-0-1, D-0-2, D-A-1, D-A-2, D-A-3 in original data.table.
So the final melted data will have the following columns chrom pos strand samples measure value.
could you pls help?
here is code i'm using
# Create a melted version for AVG, MED and samples
melted_AVG_MED <- melt(consensus_hiQ_CpGs, id.vars = c("chrom", "pos", "strand"),
measure.vars = c("AVG", "MED"),
variable.name = "measure", value.name = "value")
pls see sample data
structure(list(chrom = c("chr16", "chr9", "chr2", "chr2", "chr2",
"chr5", "chr4", "chr8", "chr7", "chr19"), pos = c(45610432L,
114912823L, 120609324L, 180012622L, 76370138L, 18336978L, 23044573L,
88382377L, 89749892L, 55697045L), strand = c("+", "-", "-", "-",
"-", "-", "-", "-", "+", "-"), `D-0-1` = c(17L, 27L, 20L, 15L,
23L, 12L, 23L, 17L, 23L, 26L), `D-0-2` = c(8L, 9L, 7L, 11L, 9L,
9L, 10L, 5L, 6L, 11L), `D-A-1` = c(16L, 23L, 21L, 12L, 17L, 19L,
18L, 17L, 17L, 16L), `D-A-2` = c(14L, 23L, 23L, 9L, 21L, 4L,
14L, 20L, 22L, 14L), `D-A-3` = c(11L, 17L, 20L, 17L, 10L, 14L,
13L, 16L, 10L, 17L), MIN = c(8L, 9L, 7L, 9L, 9L, 4L, 10L, 5L,
6L, 11L), SUM = c(66, 99, 91, 64, 80, 58, 78, 75, 78, 84), AVG = c(13.2,
19.8, 18.2, 12.8, 16, 11.6, 15.6, 15, 15.6, 16.8), MED = c(14,
23, 20, 12, 17, 12, 14, 17, 17, 16)), row.names = c(NA, -10L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x1def820>)
Maybe this could help: