[R] Missing Value And cor() function

Christian Schulz ozric at web.de
Thu Apr 24 13:23:32 CEST 2003


replace.na.m <- function (x){
    X<-mean(x,na.rm=TRUE)
    ifelse ( is.na(x)=="TRUE",X,x)
}

apply(data.frame,2,replace.na.m)

another way is using cor() and the option
 use: an optional character string giving a method for computing
          covariances in the presence of missing values.  This must be
          (an abbreviation of) one of the strings `"all.obs"',
          `"complete.obs"' or `"pairwise.complete.obs"'.

perhaps this helps you,
regards,christian


----- Original Message -----
From: <vincent.stoliaroff at socgen.com>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, April 24, 2003 12:27 PM
Subject: [R] Missing Value And cor() function


>
>
> Hi r lovers!
>
> I 'd like to apply the cor() function to a matrix which have some missing
values
> As a matter of fact and quite logically indeed it doesn't work
> Is there a trick to replace the missing value by the mean of each variable
or by any other relevant figures ?
> Or should I apply a special derivate of the cor() function, (I don't have
any idea if it exists and have some trouble to figure out how it could)
> to skip this trouble?
> Thanks a lot for any suggestions and help
>
> Vincent
>
>
>
>
>
> *************************************************************************
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
> confidentiels et etablis a l'intention exclusive de ses destinataires.
> Toute utilisation ou diffusion non autorisee est interdite.
> Tout message electronique est susceptible d'alteration.
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite au
> titre de ce message s'il a ete altere, deforme ou falsifie.
> ********
> This message and any attachments (the "message") are confidentia...
{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list