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