I am calling a function that returns a data.table with one single column.
dt <- data.table(Cmpd.Batch=(1:10), Mass=101:105, REP=1:2, CONC=rep(1:2, each=5), REPEAT=1)
dt[, makeCalcResHeader(.SD), by="CONC", .SDcols=c("Cmpd.Batch", "Mass", "REP", "CONC", "REPEAT")]
makeCalcResHeader <- function(dt){
headDT <- data.table(c("Text", paste0("curve id[", dt$CONC[1], "uM]")))
dataDT <- data.table(unique(paste(dt$Cmpd.Batch, dt$Mass, dt$REP, dt$CONC, dt$REPEAT, sep="-")))
return(rbind(headDT, dataDT))
}
But I want each returned data.table (for each CONC/REPEAT group) to be it's own separate column so that each time the function runs a column is appended to the original data.table.
Each 'section' should be its own separate column.
Is there a data.table way to do this?