toSparseM | R Documentation |
Converts the standard plpData to a sparse matrix
toSparseM(plpData, cohort = NULL, map = NULL)
plpData |
An object of type |
cohort |
If specified the plpData is restricted to the rowIds in the cohort (otherwise plpData$labels is used) |
map |
A covariate map (telling us the column number for covariates) |
This function converts the covariates Andromeda
table in COO format into a sparse matrix from
the package Matrix
Returns a list, containing the data as a sparse matrix, the plpData covariateRef and a data.frame named map that tells us what covariate corresponds to each column This object is a list with the following components:
A sparse matrix with the rows corresponding to each person in the plpData and the columns corresponding to the covariates.
The plpData covariateRef.
A data.frame containing the data column ids and the corresponding covariateId from covariateRef.
library(dplyr)
data("simulationProfile")
plpData <- simulatePlpData(simulationProfile, n=100)
# how many covariates are there before we convert to sparse matrix
plpData$covariateData$covariates %>%
dplyr::group_by(.data$covariateId) %>%
dplyr::summarise(n = n()) %>%
dplyr::collect() %>% nrow()
sparseData <- toSparseM(plpData, cohort=plpData$cohorts)
# how many covariates are there after we convert to sparse matrix'
sparseData$dataMatrix@Dim[2]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.