Re: [R] Sorting a Data Frame

2016-01-26 Thread Bert Gunter
... > mydf[2] # ??? B 1 4 2 5 3 6 A data frame is "really" a list of columns, so giving a single value returns that column. False. It returns a data frame consisting of a single column = a list containing a single component. mydf[[2]] returns a single component/column. While these differ

Re: [R] Sorting a Data Frame

2016-01-26 Thread Sarah Goslee
On Tue, Jan 26, 2016 at 4:24 PM, Robert Sherry wrote: > > Thank you for the response. As expected, the following expression worked: > df[order(df$x),] This says to sort the rows, and leave the columns alone. Subsetting a 2-dimensional object is via [rows, columns] > I would expect the follo

Re: [R] Sorting a Data Frame

2016-01-26 Thread Robert Sherry
Thank you for the response. As expected, the following expression worked: df[order(df$x),] I would expect the following expression to work also: df[order(df$x)] However it does not. That is, the comma is needed. Please tell me why the comma is there. Thanks Bob On 1/26/2016 8:19 A

Re: [R] Sorting a Data Frame

2016-01-26 Thread S Ellison
> On 23.01.2016 01:21, Robert Sherry wrote: > > In R, I run the following commands: > > df = data.frame( x=runif(10), y=runif(10) ) > > df2 = df[order(x),] > > > You use another x from your workspace, you actually want to > > > df2 = df[order(df[,"x"]),] or df[order(df$x),] And

Re: [R] Sorting a Data Frame

2016-01-22 Thread Uwe Ligges
On 23.01.2016 01:21, Robert Sherry wrote: In R, I run the following commands: df = data.frame( x=runif(10), y=runif(10) ) df2 = df[order(x),] You use another x from your workspace, you actually want to df2 = df[order(df[,"x"]),] Best, Uwe Ligges The first, as I would expect

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Sarah Goslee
Spring 0.1927715 > #16 Spring 0.1927715 > > The process you describe does not get me there > > Any other recommendations? > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: Thursday, October 11, 2012 10:33 AM > To: ROLL Josh F > Cc: R help >

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread arun
ly, the Obs column has only 4 values.  Do you want to get the means??? A.K. - Original Message - From: ROLL Josh F To: 'arun' Cc: R help Sent: Thursday, October 11, 2012 1:42 PM Subject: RE: [R] Sorting a data frame by specifying a vector Sorry if I wasn't clear but th

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Bert Gunter
Winter 0.9318599 > #10 Winter 0.9318599 > #14 Winter 0.9318599 > #4 Spring 0.1927715 > #8 Spring 0.1927715 > #12 Spring 0.1927715 > #16 Spring 0.1927715 > > Any other thoughts? > > JR > > > -Original Message- > From: Bert Gunter [mailto:gunter.ber

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread ROLL Josh F
tober 11, 2012 10:33 AM To: ROLL Josh F Cc: R help Subject: Re: [R] Sorting a data frame by specifying a vector Hi, In your dataset, it seems like it is already ordered in the way you wanted to. df.. <- data.frame(Season=rep(c("Summer","Fall","Winter","Spring&

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread arun
Hi, In your dataset, it seems like it is already ordered in the way you wanted to. df.. <- data.frame(Season=rep(c("Summer","Fall","Winter","Spring"),4),Obs= runif(length(rep(c("Summer","Fall","Winter","Spring"),4 #Suppose the order you want is:  vec2<-c("Summer","Winter","Fall","Spring") df1

Re: [R] Sorting a data frame by specifying a vector

2012-10-11 Thread Bert Gunter
?order df[order(yourcolumn, ] -- Bert On Thu, Oct 11, 2012 at 10:08 AM, LCOG1 wrote: > Hello all, >I cannot seem to figure out this seemingly simple procedure. > > I want to sort a data frame by a specified character vector. > > So for : > > df.. <- data.frame(Season=rep(c("Summer","Fall","

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread Tim Smith
-help@r-project.org Sent: Tue, June 7, 2011 10:05:37 AM Subject: Re: [R] Sorting a data frame with values of different lengths Also, I tried changing a line to store W as numeric: sample_info<-c(pds_gagehandles[i],p,as.numeric(sample_W)) But it is still sorting incorrectly: > W_table[order(W

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread William Armstrong
Thanks for catching that, Sarah. It seems like the problem was that I was using the c() function to combine terms (including W) that I was adding to a data frame. This caused R to convert the numeric W to a character string. I fixed this by using data.frame() and then rbind() instead of c() and

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread Sarah Goslee
Hi, On Tue, Jun 7, 2011 at 10:01 AM, William Armstrong wrote: > Hi Sarah, > > str(W_table) gives me: > >> str(W_table) > 'data.frame':   11 obs. of  3 variables: >  $ pds_gagehandles.i.: Factor w/ 1 level "mibe": 1 1 1 1 1 1 1 1 1 1 ... >  $ p                 : chr  "1" "2" "3" "4" ... >  $ W    

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread William Armstrong
Also, I tried changing a line to store W as numeric: sample_info<-c(pds_gagehandles[i],p,as.numeric(sample_W)) But it is still sorting incorrectly: > W_table[order(W_table$as.numeric.W.),] pds_gagehandles.i. p as.numeric.W. 8mibe 81004.5 1mibe 1

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread William Armstrong
Hi Sarah, str(W_table) gives me: > str(W_table) 'data.frame': 11 obs. of 3 variables: $ pds_gagehandles.i.: Factor w/ 1 level "mibe": 1 1 1 1 1 1 1 1 1 1 ... $ p : chr "1" "2" "3" "4" ... $ W : chr "746" "870.5" "767" "1066" ... here is the script I am usi

Re: [R] Sorting a data frame with values of different lengths

2011-06-07 Thread Sarah Goslee
Hi, It looks to me that your data frame is being sorted as text. What does str(W_table) show? How was W_table created? Your W column appears to not be numeric. Sarah On Tue, Jun 7, 2011 at 9:51 AM, William Armstrong wrote: > Hi all, > > I am attempting to run a script in which I permute my da

Re: [R] Sorting a Data Frame by hybrid string / number key

2011-02-03 Thread William Dunlap
To sort a character vector in a desired order you can convert it to a factor with the levels in the desired order. To sort strings like "2" and "11" in numerical order, use convert them to numbers with as.numeric. To sort by two variables, using the second to break ties in the first, use data[ord

Re: [R] Sorting a Data Frame by hybrid string / number key

2011-02-03 Thread David Winsemius
On Feb 3, 2011, at 10:12 AM, Alastair wrote: Hi, I'm trying to present a table of some experimental data, and I want to order the rows by the instance names. The issue I've got is that there are a variety of conventions for the instance names (e.g. competition01, competition13, small_1, bi

Re: [R] sorting a data frame by rownames

2008-07-08 Thread Jorge Ivan Velez
Dear Michael, Is this what you are looking for? ex.dat$rn=as.numeric(rownames(ex.dat)) ex.dat # Are new3 and ex.dat equals? all.equal(new3,ex.dat) [1] TRUE HTH, Jorge On Tue, Jul 8, 2008 at 10:58 PM, Michael Rennie <[EMAIL PROTECTED]> wrote: > Hi there, > > I'm sure there's an easy answer to

Re: [R] sorting a data frame by rownames

2008-07-08 Thread Rolf Turner
Can't you just do newdat <- newdat[order(row.names(newdat)),] Or am I missing something? cheers, Rolf Turner On 9/07/2008, at 2:58 PM, Michael Rennie wrote: Hi there, I'm sure there's an easy answer to this, and I can't wait to see it. The question: is the