[R] Problems with NA's
Thomas L Jones, PhD
jones3745 at verizon.net
Tue Nov 20 04:18:58 CET 2007
Difficulty handling NA's:
Assume that I have a numeric vector y. For simplicity, assume that it has 10
elements. Assume that the third element has the value NA. I give it the
following:
NA_test <- function (){
y <- numeric (10)
y [3] <- NA
if (y [3] != NA){(print ("no")}
print ("Leaving NA_test")
return ()
}# End of function
-------------------------------------------------------------
Unfortunately, things become confused involving the NA element.
Here is the output, starting with the loading process:
----------------------------------------------------------
> NA_test <- function (){
+ y <- numeric (10)
+ y [3] <- NA
+ if (y [3] != NA){(print ("no")}
Error: syntax error in:
"y [3] <- NA
if (y [3] != NA){(print ("no")}"
> print ("Leaving NA_test")
[1] "Leaving NA_test"
> return ()
Error: no function to return from, jumping to top level
> }# End of function
Error: syntax error in "}"
>
---------------------------------------------------------------------
I have enclosed the print operation in braces to avoid possible problems
with it.
Your advice?
Tom Jones
More information about the R-help
mailing list