[R] order with NAs

kjetil halvorsen kjetilh at umsanet.edu.bo
Tue Sep 24 18:29:09 CEST 2002


You want argument na.last to order(). Since you use rev() aftervards,
you want na.last=FALSE.

Kjetil Halvorsen

Remigijus Lapinskas wrote:
> 
> Dear All,
> 
> I have the test results in the following form
> 
> > test <- data.frame(Name=letters[1:5],Score=c(7,NA,5,NA,10))
> > test
>   Name Score
> 1    a     7
> 2    b    NA
> 3    c     5
> 4    d    NA
> 5    e    10
> 
> I want to rate Names by Score. However, NAs pop up to the
> upper rows when doing
> 
> > data.frame(Rating=1:dim(test)[1],test[rev(order(test$Score)),])
>   Rating Name Score
> 4      1    d    NA
> 2      2    b    NA
> 5      3    e    10
> 1      4    a     7
> 3      5    c     5
> 
> Is there an elegant way to place NAs in the lowest rows? And BTW how
> can I remove the first column of 4, 2, 5 etc?
> 
> Best regards,
>  Remigijus                          mailto:remigijus.lapinskas at maf.vu.lt
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list