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

Petr Pikal petr.pikal at precheza.cz
Fri Feb 21 14:36:03 CET 2003


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




More information about the R-help mailing list