[datatable-help] "ungrouping" a data.table
statquant3
statquant at outlook.com
Fri Jan 8 15:23:23 CET 2016
dtUngroup <- function(DT){
colClasses <- lapply(DT,FUN=class)
listCols <- which(colClasses=='list')
if(length(listCols)>0){
nonListCols <- setdiff(colnames(DT),listCols)
nbListElem <- unlist(DT[,lapply(.SD,FUN=lengths),.SDcols=(listCols[1L])])
DT1 <- DT[,lapply(.SD,FUN=rep,times=(nbListElem)),.SDcols=(nonListCols)]
DT1[,(listCols):=DT[,lapply(.SD,FUN=function(x)
do.call('c',x)),.SDcols=(listCols)]]
return(DT1)
}
return(DT)
}
This works... still 20x slower than the equivalent in kdb
--
View this message in context: http://r.789695.n4.nabble.com/ungrouping-a-data-table-tp4716265p4716269.html
Sent from the datatable-help mailing list archive at Nabble.com.
More information about the datatable-help
mailing list