Re: [R] function to replace missing values with median value?

From: Gabor Csardi <csardi_at_rmki.kfki.hu>
Date: Thu 04 May 2006 - 03:15:53 EST

sz <- function(x) ifelse(is.na(x), median(x, na.rm=TRUE), x)

Gabor

On Wed, May 03, 2006 at 10:06:40AM -0700, r user wrote:
> 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?
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Csardi Gabor <csardi@rmki.kfki.hu>    MTA RMKI, ELTE TTK

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu May 04 03:19:42 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 May 2006 - 04:09:58 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.