as.matrix.list: Converts a list to a matrix, padding vectors with NA to fit.

Description Usage Arguments Details Value Examples

View source: R/as.matrix.list.R

Description

This function cbinds the elements of a list together into a matrix. Elements shorter than the longest element are padded with NA values to fill out the matrix. If the elments themselves are lists, a specific sub-element can be extracted by name using the element argument.

Usage

1
2
## S3 method for class 'list'
as.matrix(x, element = NULL, ...)

Arguments

x

list to be converted to a matrix

element

sub-element of each list to extract before converting to matrix

...

additional arguments (ignored; included for compatibility)

Details

This is a convenience function intended primarily to make it easy to overplot a list of similar objects all at once using matplot. The elements are padded out to a length of N by indexing them from 1:N; this works sensibly for vectors, but may produce unexpected results if the (sub-) elements of your list are some other kind of object.

Value

a matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
a <- seq(5,10)
b <- rev(a)
N <- a * 100
x <- mapply(function(f,g){f + seq(g)/g}, a, N)
y <- mapply(rbeta, N, a, b)
z <- lapply(y, sort)

str(y)

matplot(as.matrix(x), as.matrix(z), pch=1)

d <- lapply(y, density, na.rm=TRUE)
matplot(as.matrix(d, "x"), as.matrix(d, "y"), type='l')

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.