Skip to content
Prev 311490 / 398503 Next

lists as matrix cells ?

A matrix may only contain one data type. By not specifying when you
created m, it was filled with logical values of NA.

A logical value can't hold a list.

You can see that with
str(m)
which returns:
logi [1:3, 1:2] NA NA NA NA NA NA
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:3] "Row_one" "Row_two" "Row_three"
  ..$ : chr [1:2] "Column_A" "Column_B"

If you were to instead specify that the elements of m should be list objects:


m <- matrix(list(), nrow=3, ncol=2,
  dimnames=list(
    c("Row_one", "Row_two", "Row_three"),
    c("Column_A", "Column_B")
  )
)

(and check with str(m) again)

then you can replace those list objects with other list objects
m[[ 1,1 ]] <- list(1.0, 2.0)


Please also note that [ and [[ are not the same thing.

I'm not sure this is the most efficient solution for your problem, but
since I'm not really sure what your problem is I solved the question
asked rather than the underlying problem.

Sarah
On Wed, Nov 21, 2012 at 11:11 AM, Asis Hallab <asis.hallab at gmail.com> wrote:
--
Sarah Goslee
http://www.functionaldiversity.org