sparse_mat: Create sparse matrix from a list of integer or character...

View source: R/sparse_mat.R

sparse_matR Documentation

Create sparse matrix from a list of integer or character vectors

Description

This functions returns a binary matrix

Usage

sparse_mat(vlist, vorder)

Arguments

vlist

The vlist a list consists from character, integer or binary vectors.

vorder

logical: If 'vlist' consists of an ordered vector or not. The default value is FALSE.

Value

a data frame of sparse matrix which first column unique elements of a list

Examples

set.seed(1)
int_list <- lapply(1:6, function(i) abs(as.integer(rnorm(6, mean = i))))
bin_list <- lapply(1:6, function(i) round(runif(4, 0, 1)))
chr_list <- lapply(1:6, function(i) sample(letters, size = 4))
ochr_list <- lapply(1:6, function(i) setNames(sample(c('A','B','C'), 4, replace =TRUE), 1:4))
ochr_dat <- data.frame(ochr_list, stringsAsFactors = FALSE)
sparse_mat(int_list); sparse_mat(bin_list);
sparse_mat(chr_list); sparse_mat(ochr_list, vorder =TRUE)
sparse_mat(ochr_dat, vorder =TRUE)

shkonishi/rsko documentation built on Feb. 21, 2023, 5:12 a.m.