r - Adding a matrix to a list -
i r newbie. trying add matrix list before returning function.
a <- matrix(4,4,4) x <- list(l=1, m=2) x["n"] <-
the above ends following warning message , 1 number matrix gets added list.
warning message: in x["n"] <- : number of items replace not multiple of replacement length
how can this? nice if how don't have specify dimensions of matrix before hand.
use $
extraction:
> x$n <- > x $l [1] 1 $m [1] 2 $n [,1] [,2] [,3] [,4] [1,] 4 4 4 4 [2,] 4 4 4 4 [3,] 4 4 4 4 [4,] 4 4 4 4
or [[
extraction:
> x$n <- null > x[["n"]] <- > x $l [1] 1 $m [1] 2 $n [,1] [,2] [,3] [,4] [1,] 4 4 4 4 [2,] 4 4 4 4 [3,] 4 4 4 4 [4,] 4 4 4 4
Comments
Post a Comment