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 to split a list based on distinct element

I would like to split a list according to each distinct element

mylist <- list("first","first","second")

### What I would like
# A first list
list("first","first")
# A second list
list("second")

>Solution :

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

If you do the one-liner:

list2env(split(mylist, unlist(mylist)), globalenv())

Then you have the two lists in your global environment:

dput(first)
#> list("first", "first")

dput(second)
#> list("second")

Created on 2023-01-25 with reprex v2.0.2

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