Sorry, there was a stupid cut & paste mistake (missing parentheses in
return statement...)
ConvertMissingToNA <- function(values)
{
values[values == - | values == -99] <- NA
return(values)
}
Peter
__
R-help@r-project.org mailing list
What you want is
ConvertMissingToNA <- function (values) {
values[ values == - | values == -99] <- NA
return( values )
}
To see why your version doesn't do what you wanted, maybe it helps to
consider the following?
x <- 1:10
y <- (x[3:6] <- 99)
y ## 99
(It's perhaps not entirely o
Quoting "Hutchinson,David [PYR]" <[EMAIL PROTECTED]>:
I wrote a simple function to change values of a matrix or vector to NA
based on the element value being - or -99. I don't understand
why the function returns a unit vector (NA) instead of setting all
values in the vector which have -9
try this -- you have to return the entire vector:
ConvertMissingToNA <- function (values) {
values[ values == - | values == -99] <- NA
values
}
d <- floor(runif(10, 1, 100))
pos <- floor (runif(5, 1, 10))
d[pos] <- -
pos <- floor (runif(2, 1, 10))
d[pos] <- -99
print (d)
# now
Hi R-Users,
I wrote a simple function to change values of a matrix or vector to NA
based on the element value being - or -99. I don't understand
why the function returns a unit vector (NA) instead of setting all
values in the vector which have - or -99 to NA. When I apply the
func
5 matches
Mail list logo