Last active
July 18, 2026 20:12
-
-
Save jonesor/cd1176e4ce5104f8869531ad99add368 to your computer and use it in GitHub Desktop.
How to subset the COMPADRE/COMADRE matrix database based on the matrices themselves. This example counts NA values in the F matrix and uses that to subset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How to subset the matrix database based on the matrices themselves. | |
| # This example counts NA values in the F (fecundity) matrix of each population | |
| # and uses that to subset. Uses the modern Rcompadre CompadreDB API. | |
| library(Rcompadre) | |
| compadre <- cdb_fetch("compadre") | |
| # matF() returns a list of the F matrices, one per row of the database. | |
| # Count the NA values in each, and store as a new metadata column. | |
| compadre$NAinFmat <- sapply(matF(compadre), function(m) sum(is.na(m))) | |
| table(compadre$NAinFmat) | |
| # Keep only populations whose F matrix has no NA values. | |
| x <- subset(compadre, NAinFmat == 0) | |
| table(x$NAinFmat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment