I'm using R 3.5.1
I think this is a simple issue, but I'm not super familiar with R.
I have a data.frame object that looks like this
COL1 COL2 COL3
A blah 3
A abc 4
A def 42
B xyz 10
B aaa 3
C pdq 19
I want to transform the data.table to look like this
COLA COLACount COLB COLBCount COLC COLCCount
blah 3 xyz 10 pdq 19
abc 4 aaa 3
def 42
I'm not sure where to begin with this (or what to call it). I have considered doing the following:
But I have a feeling that there might be an r package/method that simplifies this procedure.
Thank you for any suggestions.
cbind.fill <- function(...){
nm <- list(...)
nm <- lapply(nm, as.matrix)
n <- max(sapply(nm, nrow))
do.call(cbind, lapply(nm, function (x)
rbind(x, matrix(, n-nrow(x), ncol(x)))))
} #code from package rowr
do.call(cbind.fill, split(dt, dt$COL1))