Tutorial by Examples

data.table offers a wide range of possibilities to reshape your data both efficiently and easily For instance, while reshaping from long to wide you can both pass several variables into the value.var and into the fun.aggregate parameters at the same time library(data.table) #v>=1.9.6 DT <- ...
data.table extends reshape2's melt & dcast functions (Reference: Efficient reshaping using data.tables) library(data.table) ## generate some data dt <- data.table( name = rep(c("firstName", "secondName"), each=4), numbers = rep(1:4, 2), value = rnorm(8) ) ...
Melting: The basics Melting is used to transform data from wide to long format. Starting with a wide data set: DT = data.table(ID = letters[1:3], Age = 20:22, OB_A = 1:3, OB_B = 4:6, OB_C = 7:9) We can melt our data using the melt function in data.table. This returns another data.table in long...
Casting: The Basics Casting is used to transform data from long to wide format. Starting with a long data set: DT = data.table(ID = rep(letters[1:3],3), Age = rep(20:22,3), Test = rep(c("OB_A","OB_B","OB_C"), each = 3), Result = 1:9) We can cast our data using the...
A common refrain in R goes along these lines: You should not have a bunch of related tables with names like DT1, DT2, ..., DT11. Iteratively reading and assigning to objects by name is messy. The solution is a list of tables of data! Such a list looks like set.seed(1) DT_list = lapply(setNam...

Page 1 of 1