[R] Odp: what is there in a numeric (0)?
petr.pikal at precheza.cz
Thu Nov 27 13:35:42 CET 2008
r-help-bounces at r-project.org napsal dne 27.11.2008 11:48:32:
> I will repeat my question :what is there in a numeric(0)?
> In a function, I have several matrices with dimensions 288x1, also
> with dimensions
> 0x1 (numeric(0)).
> But I really do not know in which matrix there are elements or not.
> So, these matrices that do not contain anything, if I am saying this
> correctly, I would like to make them
> matrices with the same dimensions as the first ones but with NA
> the ones with elements to remain as they
> For this reason, I thought to use the ifelse command. But I have
> determining the arguments of this ifelse...
> I tried to use:
> A1 <- ifelse(nrow(A)==0,matrix(rep(NA,288),288,1),A)
> If A is a matrix with elements, then I get a A1 matrix with replicated
> times its first element, but I want the
> initial A matrix. If A is a matrix with no elements (numeric(0)) then I
> only 1 NA.
It is not a work for ifelse but for if. You want to test only one
comparison not a vector of values.
if(nrow(mat)==0) A1 <- matrix(NA, 288,1) else A1 <- A
> So, how can I test if there are elements in my matrix and if there are
> return itself the matrix and if there are not to get a matrix 288x1 with
> Thank you for your time!
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help