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

Published: 21 July 2021
on channel: Statistics Globe
1,993
21

How to transform data frame variables to list elements in the R programming language. More details: https://statisticsglobe.com/convert-d...
R code of this video:

data <- data.frame(x1 = 5:9, # Create example data
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:
Facebook:   / statisticsglobecom  
LinkedIn:   / statisticsglobe  
Twitter:   / joachimschork  


On this page of the site you can watch the video online Convert Data Frame Columns to List Elements in R (2 Examples) | Adapt One / Each Variable | colnames with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 21 July 2021, share the link with friends and acquaintances, this video has already been watched 1,993 times on youtube and it was liked by 21 viewers. Enjoy your viewing!