Andra Isan
2011-Aug-11 00:23 UTC
[R] Question about NULL matrix? Can I define a NULL matrix in R?
Hi All, I would like to create a matrix in R but I dont know the size of my matrix. I only know the size of the columns but not the size of the rows. So, is there any way to create a dynamic matrix of size NULL by n_cols? and then add to that matrix? I know for a vector, I can do this: x= NULL but is there any way to do the same for a matrix as well? Thanks a lot,Andra [[alternative HTML version deleted]]
David Winsemius
2011-Aug-11 01:11 UTC
[R] Question about NULL matrix? Can I define a NULL matrix in R?
On Aug 10, 2011, at 8:23 PM, Andra Isan wrote:> Hi All, > I would like to create a matrix in R but I dont know the size of my > matrix. I only know the size of the columns but not the size of the > rows. So, is there any way to create a dynamic matrix of size NULL > by n_cols? and then add to that matrix? > I know for a vector, I can do this: x= NULL but is there any way to > do the same for a matrix as well?No. You cannot make an R matrix without knowing the number of rows. By definition an R matix has two integer dimensions. Alternatives: You can rbind to an existing matrix, or you can make a larger than necessary matrix filled with NA's and then fill and later extract a subset of the rows. -- David Winsemius, MD West Hartford, CT