An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130316/4e36c08d/attachment.pl>
missing values in an array
4 messages · arun, Berend Hasselman, Ray Cheung
HI, Try this: set.seed(25) arr1<- array(sample(c(1:40,NA),60,replace=TRUE),dim=c(5,4,3)) arr1[,,sapply(seq(dim(arr1)[3]),function(i) all(!is.na(arr1[,,i])))] #???? [,1] [,2] [,3] [,4] #[1,]??? 2?? 13?? 34?? 17 #[2,]?? 19??? 3?? 15?? 39 #[3,]??? 4?? 25?? 10?? 16 #[4,]??? 7?? 22??? 5??? 7 #[5,]?? 12?? 10?? 35??? 6 #2nd case set.seed(46) arr2<- array(sample(c(1:40,NA),60,replace=TRUE),dim=c(5,4,3)) arr2[,,sapply(seq(dim(arr2)[3]),function(i) all(!is.na(arr2[,,i])))] #, , 1 #???? [,1] [,2] [,3] [,4] #[1,]??? 8?? 27?? 11?? 28 #[2,]?? 10?? 37??? 5?? 40 #[3,]?? 24?? 25?? 28??? 6 #[4,]?? 15?? 37??? 3?? 25 #[5,]?? 10?? 39?? 32?? 23 #, , 2 # ???? [,1] [,2] [,3] [,4] #[1,]?? 14??? 2??? 8?? 27 #[2,]?? 10?? 39?? 37??? 4 #[3,]??? 9?? 36?? 15??? 6 #[4,]?? 33?? 16?? 20?? 32 #[5,]?? 21??? 6?? 28?? 15 A.K. ----- Original Message ----- From: Ray Cheung <ray1728 at gmail.com> To: R help <r-help at r-project.org> Cc: Sent: Friday, March 15, 2013 12:08 PM Subject: [R] missing values in an array Dear All, I've an array with some missing values (NA) in between. I want to remove that particular matrix if a missing value is detected. How can I do so? Thank you very much. Best regards, Ray ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 15-03-2013, at 17:08, Ray Cheung <ray1728 at gmail.com> wrote:
Dear All, I've an array with some missing values (NA) in between. I want to remove that particular matrix if a missing value is detected. How can I do so? Thank you very much.
It is not clear what the dimension of your array is. If your array/matrix is two dimensional, then then any(is.na(A)) # A is the name of the array/matrix will return TRUE is at least one element of A is NA. And then you can delete A. If you array has three dimensions then you'll have to look at arun's solution. Berend
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130316/e47b3c72/attachment.pl>