I know the split command is the easiest way to turn a df into a list of df objects, but how can they be assigned to different (seperated) dataframes?
df.List <- split(df, df$column)
I know the split command is the easiest way to turn a df into a list of df objects, but how can they be assigned to different (seperated) dataframes?
df.List <- split(df, df$column)
Look at the function list2env
. Try:
list2env(split(df, df$column), envir = .GlobalEnv)
Hereby my solution (example with the iris dataset)
two way:
list_df <- split(iris, iris$Species) #split the dataset into a list of datasets based on the value of iris$Species
list2env(list_DF, envir= .GlobalEnv) #split the list into separate datasets
one way:
list2env(split(iris, iris$Species), envir = .GlobalEnv)
Or you can assign custom names for the new datasets with a for
loop:
iris_split <- split(iris, iris$Species)
new_names <- c("one", "two", "three")
for (i in 1:length(iris_split)) {
assign(new_names[i], iris_split[[i]])