Convert Matrix to List of Column-Vectors in R (2 Examples) | Split & Divide | lapply() & seq_len()

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

data <- matrix(1:15, ncol = 3) # Create example matrix

my_list1 <- split(data, # Split matrix into list
rep(1:ncol(data),
each = nrow(data)))
my_list1 # Print list of column-vectors

my_list2 <- lapply(seq_len(ncol(data)), # Split matrix into list
function(x) data[ , x])
my_list2 # Print list of column-vectors

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

cool.. It would be even better if you can try to explain how these functions work. Thank you

razorscythe