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)) > testName 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 24 Sep 2002, Remigijus Lapinskas wrote:> > 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?If you look at the help page for order() you will find the option to put NAs at the end. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._