[R] setting elements to NA across an array

From: Dr Carbon <drcarbon_at_gmail.com>
Date: Thu 28 Jul 2005 - 03:19:21 EST


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
  foo

Now I want to set foo[2,2,] <- NA and foo[3,5,] <- NA. How can I build a logical statement to do this?



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 28 03:30:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:05 EST