[R] missing values in an array
arun
smartpink111 at yahoo.com
Fri Mar 15 17:20:53 CET 2013
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.
More information about the R-help
mailing list