0

We have a list which contain sublists, and these sublists contain Seurat objects. In each object metadata we have a variable which we'd like group based on. We'd like to group these objects into a new list based on this variable. Any help on appending objects to a predefined list based on this variable will be appreciated.

To visualise it we have:

list
 listA
  object1@metadata$variable1["X"]
  object2@metadata$variable1["Y"]
  object3@metadata$variable1["Z"]
  object4@metadata$variable1["X"]
  object5@metadata$variable1["Y"]
 listB
  object1@metadata$variable1["X"]
  object2@metadata$variable1["Y"]
  object3@metadata$variable1["Y"]
 listC
  object1@metadata$variable1["X"]
  object2@metadata$variable1["Y"]
  object3@metadata$variable1["X"] 
 listD
  object1@metadata$variable1["X"]
  object2@metadata$variable1["X"]
  object3@metadata$variable1["Z"]
  object4@metadata$variable1["Z"]

and we want to append these objects to a new list based on variable1, i.e all the listA variable1["X"] objects together, listA variable1["Y"] objects together, etc.

We've tried to use pmatch to match the string of the metadata variable to the string in the predefined list.

Any other strategies are very much welcome.

jet28
  • 1
  • 1
    Hi, welcome to Stackoverflow. It would really help if you could provide some reproducible (mockup) data to work with. – VvdL Dec 06 '22 at 15:09
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's hard to test with just the outline you've provided. – MrFlick Dec 06 '22 at 15:09

0 Answers0