[R] more on lm(y~x) question: removing NA´s

Christoph Scherber Christoph.Scherber at uni-jena.de
Tue May 4 15:55:09 CEST 2004


actually, the situation is much more complicated. I am producing 
multiple graphs within a "for" loop. For some strange reason, the 
plotting routine always stops once lm(y~x) encounters more than one 
missing value (I have marked the important bit with "***********"):

par(mfrow=c(5,5))
p_seq(3,122,2)
i_0
k_0
number_0
for (i in p) {
   j_foranalysis[93:174,i+1]
   k_foranalysis[93:174,i]  
   df_data.frame(j,k)
   mainlab1_substring(names(foranalysis[i]),2,8)
   mainlab2_"; corr.:"
   mainlab3_round(cor(j,k,na.method="available"),4)
   mainlab4_"; excl.Mono:"
   mainlab5_round(cor(j[j<0.9],k[j<0.9],na.method="available"),4)
   mainlab_paste(mainlab1,mainlab2,mainlab3,mainlab4,mainlab5)
   plot(k,j,main=mainlab,xlab="% of total biomass",ylab="% of total 
cover",pch="n")
   for (k in 1:length(foranalysis[93:174,i])) 
number[k]_substring(plotcode[foranalysis[k,1]],1,5)
   text(foranalysis[93:174,i],foranalysis[93:174,i+1],number)
**********************************
   model_lm(j~k,na.action=na.exclude])
**********************************
   abline(model)
   abline(0,1,lty=2)
    }

Does anyone have any suggestions on this?

Best regards
Chris.,




Liaw, Andy wrote:

>By (`factory') default that's done for you automagically, because
>options("na.action") is `na.omit'.
>
>If you really want to do it `by hand', and have the data in a data frame,
>you can use something like:
>
>lm(y ~ x, df[complete.cases(df),])
>
>HTH,
>Andy
>
>  
>
>>From: Christoph Scherber
>>
>>Dear all,
>>
>>I have a data frame with different numbers of NA´s in each 
>>column, e.g.:
>>
>>x       y  
>>1      2
>>NA  3
>>NA  4
>>4     NA
>>1     5
>>NA NA
>>
>>
>>I now want to do a linear regression on y~x with all the NA´s 
>>removed. 
>>The problem now is that is.na(x) (and is.na(y) obviously 
>>gives vectors 
>>with different lengths. How could I solve this problem?
>>
>>Thank you very much for any help.
>>
>>Best regards
>>Chris
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! 
>>http://www.R-project.org/posting-guide.html
>>
>>
>>    
>>
>
>
>------------------------------------------------------------------------------
>Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
>------------------------------------------------------------------------------
>
>  
>




More information about the R-help mailing list