How to initialize an empty or sample data table?

Often, especially when asking questions about stack overflows, I would like to create a data table with dummy values. However, I'm not sure how to create a data table that is either empty or has dummy values. How to do it?

+4
source share
1 answer

To create an empty data table, use:

DT <- data.table(
variable1 = integer(),
variable2 = character(),
variable3 = numeric()
)

To create a data table with fake data, use:

DT <- data.table(
variable1 = 1:5,
variable2 = c(1,2,5,6,8),
variable3 = c("a","b","c","d","e")
)
+10
source

All Articles