[R] replacing values in a vector
Sven Garbade
garbade at psy.uni-muenchen.de
Thu Jul 26 14:27:44 CEST 2001
Jens Nieschulze wrote:
>
> On Thu, 26 Jul 2001, Sven Garbade wrote:
>
> > Hi all,
> >
> > there is a vector v with several NAs. I want to create a new vector n of
> > the same length as v and the same NAs as in v and tried this:
> >
> > n <- vector(length=length(v), mode="numeric")
> > replace(n, which(is.na(v)), NA)
> >
> > but this does't work, all values in n are 0. What went wrong?
>
> > replace
> function (x, list, values)
> {
> x[list] <- values
> x
> }
> from the function body I gues you should use
>
> > replace(n, which(is.na(v)), NA)->n
>
> instead because I assume that x is a local variable
> so the global n wouldn't be changed by replace()
oh, of course... Thanks!
Sven
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list