Re: [R] Simple order() data frame question.

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Thu, 12 May 2011 06:00:16 -0700


Ah, this never would have occured to me. It's rather obvious now but of course, I'll forget it again. Note to self: Put it in the cribsheet.

Thanks very mcuy

> From: Nick Sabbe <nick.sabbe_at_ugent.be>
> Subject: RE: [R] Simple order() data frame question.

> To: "'John Kane'" <jrkrideau_at_yahoo.ca>, "'R R-help'" <r-help_at_stat.math.ethz.ch>
> Received: Thursday, May 12, 2011, 8:50 AM
> Try
> (df1[order(-df1[,2]),])
> Adding the minus within the [ leaves out the column (in
> this case column 2).
> See ?"[".
>
> HTH.
>
>
> Nick Sabbe
> --
> ping: nick.sabbe_at_ugent.be
> link: http://biomath.ugent.be
> wink: A1.056, Coupure Links 653, 9000 Gent
> ring: 09/264.59.36
>
> -- Do Not Disapprove
>
>
>
>
> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org]
> On
> Behalf Of John Kane
> Sent: donderdag 12 mei 2011 14:33
> To: R R-help
> Subject: [R] Simple order() data frame question.
>
> Clearly, I don't understand what order() is doing and as
> ususl the help for
> order seems to only confuse me more. For some reason I just
> don't follow the
> examples there. I must be missing something about the data
> frame sort there
> but what?
>
> I originally wanted to  reverse-order my data frame
> df1 (see below) by aa (a
> factor) but since this was not working I decided to
> simplify and order by bb
> to see what was haqppening!!
>
> I'm obviously doing something stupid but what?
>
> (df1 <- data.frame(aa=letters[1:10],
>      bb=rnorm(10)))
> # Order in acending order by bb
> (df1[order(df1[,2]),] ) # seems to work fine
>
> # Order in decending order by bb.
> (df1[order(df1[,-2]),])  # does not seem to work
>
>
> ===============================================================
> sessionInfo()
> R version 2.13.0 (2011-04-13)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_Canada.1252 
> LC_CTYPE=English_Canada.1252
> LC_MONETARY=English_Canada.1252
> [4] LC_NUMERIC=C           
>        
> LC_TIME=English_Canada.1252   
>
> attached base packages:
> [1] grid      grDevices datasets 
> splines   graphics  stats 
>    tcltk
> utils 
>    methods   base 
>    
>
> other attached packages:
> [1]
> ggplot2_0.8.9   proto_0.3-9.2   reshape_0.8.4   plyr_1.5.2
> svSocket_0.9-51 TinnR_1.0.3 
>    R2HTML_2.2     
> [8] Hmisc_3.8-3     survival_2.36-9
>
> loaded via a namespace (and not attached):
> [1] cluster_1.13.3  lattice_0.19-26
> svMisc_0.9-61   tools_2.13.0   
> >
>
> ______________________________________________
> R-help_at_r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 12 May 2011 - 13:02:46 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 May 2011 - 13:50:06 GMT.

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

list of date sections of archive