How do I get a loop which performs these actions in R?
Map 33 doesn't exist.
map1 <- dat %>%
filter(map == 1)
map2 <- dat %>%
filter(map == 2)
map3 <- dat %>%
filter(map ==3)
...
CodePudding user response:
We don't need to use multiple steps, just use split
to return a list
of data.frames
lst1 <- split(dat, dat$map)
names(lst1) <- paste0("map", names(lst1))
It is better not to create multiple objects. But if we need, use list2env
list2env(lst1, .GlobalEnv)