oops!, I pressed the 'send' key too soon, ...
see ?replace
replace(x, is.na(x), median(x, na.rm=T))
take also a look at the function itself
> replace
function (x, list, values)
{
x[list] <- values
x
}
<environment: namespace:base>
Stefano
>-----Messaggio originale-----
>Da: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] conto di
>Guazzetti Stefano
>Inviato: Thursday, May 04, 2006 07:55 AM
>A: [EMAIL PROTECTED]; [EMAIL PROTECTED]
>Cc: [email protected]
>Oggetto: [R] R: [Re:] function to replace missing values with median
>value?]]
>
>
>there is also a replace function
>
>
> >-----Messaggio originale-----
> >Da: [EMAIL PROTECTED]
> >[mailto:[EMAIL PROTECTED] conto di
> >[EMAIL PROTECTED]
> >Inviato: Thursday, May 04, 2006 07:31 AM
> >A: [EMAIL PROTECTED]
> >Cc: [email protected]
> >Oggetto: [R] [Re:] function to replace missing values
>with median
> >value?]]
> >
> >
> >The following should work
> >
> >sz <- function(x) { ifelse(is.na(x) == F, x, median(x,
> >na.rm=TRUE)) }
> >
> >best, isaia.
> >
> >-------- Original Message --------
> >Subject: [R] function to replace missing values with
>median value?
> >Date: Wed, 3 May 2006 10:06:40 -0700 (PDT)
> >From: r user <[EMAIL PROTECTED]>
> >To: rhelp <[email protected]>
> >
> >I have a data set with ~10 variables (i.e. columns).
> >
> >I wrote this little function to replace missing values
> >with zero.
> >
> >“ sz <- function(x) { ifelse(is.na(x)==F,x,0) } “
> >
> >Can anyone help with a function that replaces missing
> >values with the median of the non-missing values?
> >
> >______________________________________________
> >[email protected] mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
> >
> >--
> >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >~ Ennio D. Isaia
> >~ Dep. of Statistics & Applied Mathematics, University of Torino
> >~ Piazza Arbarello, 8 - 10122 Torino (Italy)
> >~ Phone: +39 011 670 57 29 ~~ Fax: +39 011 670 57 83
> >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >______________________________________________
> >[email protected] mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
> >
> >
>
>______________________________________________
>[email protected] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html