[R] how to chage values in data frame to NA iside a function

Thomas W Blackwell tblackw at umich.edu
Fri Feb 21 15:04:06 CET 2003


Petr  -

Does your function return "index" or return "y" after modifying y ?
In the email, it looks as though it returns "index".  If so, the
following should work:

> df$y[ dropout(df$y) ] <- NA

-  tom blackwell  -  u michigan medical school  -  ann arbor  -



On Fri, 21 Feb 2003, Petr Pikal wrote:

> Dear all
>
> I have a function in which I would like to change some values to NA according to
> some condition.
>
> dropout<-function(y, nahr=FALSE,...) {
>
> <some stuff for computing an index>
>
> if (nahr) y[index]<<-NA
> invisible(index)
>
> }
>
> in case y is a vector all works OK but if it is a part of data frame by calling
>
> dropout(df$y) or dropout(df[,number]) no change is done.
>
> Please can you help me what is wrong with my code?
>
> By the way
>
> idx<-dropout(df$y)
> df$y[idx]<-NA
>
> works OK
>
> Thanks a lot beforehand
>
> Best regards.
>
> Petr Pikal
> Precheza a.s., Nabø.Dr.E.BeneÜe 24, 750 62 Pøerov
> tel: +420581 252 257 ; 724 008 364
> petr.pikal at precheza.cz; p.pik at volny.cz
> fax +420581 252 561
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list