Quantcast
Channel: best way to transpose data.table - Stack Overflow
Browsing all 7 articles
Browse latest View live

Answer by Japa19 for best way to transpose data.table

df <- as.data.frame(t(mydata)) is what I tried and df is a data.frame and the column names on mydata are now row names on df

View Article



Answer by PeterAU for best way to transpose data.table

The tdt function which I provide below should be faster tdt <- function(DT, transpose.col, ...) { # The transpose function is efficient, but lacks the keeping of row and colnames new.row.names <-...

View Article

Answer by Amy M for best way to transpose data.table

Here's a solution that uses a wrapper to tidy up the output of the data.table transpose function. With really large data sets this seems to be more efficient than the dcast/melt approach (I tested it...

View Article

Answer by abalter for best way to transpose data.table

The current docs show a builtin transpose method. I don't know when it was added, but apparently it was needed!

View Article

Answer by shadow for best way to transpose data.table

Here's an alternative solution that only uses data.table and that is closer to the original idea of using t to transpose. mydata[, data.table(t(.SD), keep.rownames=TRUE), .SDcols=-"col0"] ## rn V1 V2...

View Article


Answer by A5C1D2H2I1M1N2O1R2T1 for best way to transpose data.table

Why not just melt and dcast the data.table? require(data.table) dcast(melt(mydata, id.vars = "col0"), variable ~ col0) # variable row1 row2 row3 # 1: col1 11 21 31 # 2: col2 12 22 32 # 3: col3 13 23 33

View Article

best way to transpose data.table

I often need to transpose a data.table, every time it takes several lines of code and I am wondering if there's any better solution than mine. if we take sample table library(data.table) mydata <-...

View Article
Browsing all 7 articles
Browse latest View live




Latest Images