Skip to content
Prev 201844 / 398506 Next

Best way to preallocate numeric NA array?

Hi

There is one issue which I encountered recently with this type of 
behaviour, 

mat<-matrix(NA,5,4)
fix(mat)

put some number in any cell and close fix

mat
     col1 col2 col3 col4
[1,]   NA   NA   NA   NA
[2,]   NA   NA   NA   NA
[3,]   NA   NA   NA   NA
[4,]   NA   NA   NA   NA
[5,]   NA   NA   NA   NA

No value is put into mat. There is easy workaround, but it can be 
frustrating if somebody tries to find why the value is not inputed. I know 
that it is not preferred way to fill a matrix but if you have such small 
matrix and it has only few non NA values this could be used.

Maybe on help page could be some kind of explanation:

"Fix can not convert a type(mode) of its argument and therefore it is 
possible to input only values which match type of x."

or something like that

Regards
Petr


 
r-help-bounces at r-project.org napsal dne 26.11.2009 17:22:45:
numeric
http://www.R-project.org/posting-guide.html