Read 'An Introduction to R', found on the R web site. It is short and
worth reading in its entirety. Section 2.5 on missing values answers your
question:
2.5 Missing values
In some cases the components of a vector may not be completely known. When an
element or value is "not available" or a "missing value" in
the statistical sense, a place within a vector may be reserved for it by
assigning it the special value NA. In general any operation on an NA becomes an
NA. The motivation for this rule is simply that if the specification of an
operation is incomplete, the result cannot be known and hence is not available.
The function is.na(x) gives a logical vector of the same size as x with value
TRUE if and only if the corresponding element in x is NA.
> z <- c(1:3,NA); ind <- is.na(z)
Notice that the logical expression x == NA is quite different from is.na(x)
since NA is not really a value but a marker for a quantity that is not
available. Thus x == NA is a vector of the same length as x all of whose values
are NA as the logical expression itself is incomplete and hence undecidable.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org] On Behalf
> Of Yasin Gocgun
> Sent: Friday, June 21, 2013 8:59 AM
> To: r-help at r-project.org
> Subject: [R] an issue about removing "NA"s from an array
>
> Hi,*
>
> *I would like to set the entries of an array that appear as "NA"
to a
> certain integer, but did not find a way to do so. The related code is given
> below:
>
> A <- array(-1000 , dim=c(100) );
>
> for(i in 1: 100 ){
> A[i] =B[i,57] - B[i,5];
> }
>
> A [ which( A == "NA") ] <- 900;
>
> The "NA"s still appear as the entries of the array A.
>
> Can you tell me what is missing here? (I also tried setting the entries of
> A to character using "as.character" but it did not work)
>
> Thanks,
>
>
> --
> Yasin Gocgun
>
> [[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.