Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I automate this division of my data set in R?

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)
...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading