Do you have an idea to call only one specific matrix which contain a string of characters in my list of twelve matrices ? For exemple, I have my list of twelve matrices (which represent data of genetic distance between pairs of 60 individuals, a matrix is therefore 60*60) for the 12 months of the year, and I want to extract only 3 matrices for 3 months of the year.
So for that, I want to call the matrices which contain in their name "Apr", "May" or "Jun", like this : spring <- list(list.mat[["Apr"]], list.mat[["May"]], list.mat[["Jun"]])
. But because there is missing months, I want to find a function who call only the months who can possibly contain these string of charactrs in their names. I try grep
function and its derivates but it doesn't work on list of matrices...
I know there is a simple way to do that but I don't know which way to look!
I don't want to make it manually because I have more than 40 list of 12 matrices !
Thanks for any replies if you know what i'm looking for
CodePudding user response:
We may use Filter
from base R
to remove the NULL
list elements
Filter(Negate(is.null), list.mat)