verybadatthis
verybadatthis

Reputation: 1458

How do I initialize an empty or example data table?

Often, especially when asking questions on Stack Overflow, I would like to create a data table with dummy values. However, I'm not sure how to create a data table which is either empty or has dummy values. How do I do this?

Upvotes: 18

Views: 39924

Answers (1)

verybadatthis
verybadatthis

Reputation: 1458

To make an empty data table, use:

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

To make 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")
)

Upvotes: 35

Related Questions