[R] setting elements to NA across an array
jfox at mcmaster.ca
Wed Jul 27 19:37:25 CEST 2005
Dear Dr Carbon,
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Dr Carbon
> Sent: Wednesday, July 27, 2005 12:19 PM
> To: r-help at r-project.org
> Subject: [R] setting elements to NA across an array
> Please excuse what is obviously a trivial matter...
> I have a large 3-d array. I wish to set the third dimension
> (z) to NA if there are any NA values in the first two
> dimnesions (xy). So, given array foo:
> foo <- array(data = NA, dim = c(5,5,3))
> foo[,,1] <- matrix(rnorm(25), 5, 5)
> foo[,,2] <- matrix(rnorm(25), 5, 5)
> foo[,,3] <- matrix(rnorm(25), 5, 5)
> I'll set two elements to NA
> foo[2,2,1]<- NA
> foo[3,5,2]<- NA
> Now I want to set foo[2,2,] <- NA and foo[3,5,] <- NA. How
> can I build a logical statement to do this?
That should work just as you've specified it: That is, elements in all
"layers" in the second row, second column and in the the third row, fifth
column of the array should be NA. Since you posed the question, I suppose
that I'm missing something.
I hope this helps,
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide!
More information about the R-help