Convert Data Frame Columns to List Elements in R (2 Examples) | Adapt One / Each Variable | colnames

preview_player
Показать описание
R code of this video:

x2 = letters[2:6],
x3 = "X")

my_list1 <- list(data$x1) # Convert one column to list element
my_list1 # Print list

my_list2 <- list() # Create empty list

for(i in 1:ncol(data)) { # Using for-loop to add columns to list
my_list2[[i]] <- data[ , i]
}

names(my_list2) <- colnames(data) # Rename list elements

my_list2 # Print list

Follow me on Social Media:
Рекомендации по теме