I have a dataset with a categorical variable and I would like to split it into many datasets named by that categorical variable. For example, in the Titanic dataset there is an age variable. I would like to have R automatically figure out that it has two levels, Adult and Child, and create a dataset named Adult containing the Adult records and another dataset named Child containing the Child records. How can I do this with tidyverse or base R? I know that I can just filter and name each object manually, but I would like to do this programmatically for a variable with many levels.
The list2env() option worked perfectly. Thank you @gregorthomas. My final code was like this
Titanic <- data.frame(Titanic)
split(Titanic, with(Titanic, Age), drop = TRUE) |>
list2env(.GlobalEnv)