Create Empty Data Frame in R (2 Examples) | data.frame & setNames Functions in R programming

Опубликовано: 03 Февраль 2025
на канале: Statistics Globe
2,894
27

How to create an empty data frame with zero rows in the R programming language. More details here: https://statisticsglobe.com/create-em...

R programming syntax of this video:

##### Example 1 - Specify empty vectors

data_1 <- data.frame(x1 = character(), # Specify empty vectors in data.frame
x2 = numeric(),
x3 = factor(),
stringsAsFactors = FALSE)
data_1 # Print data to RStudio console


##### Example 2 - Apply setNames function

Create empty data.frame with matrix & setNames functions
data_2 <- setNames(data.frame(matrix(ncol = 3, nrow = 0)), c("x1", "x2", "x3"))