In R, I run the following commands: df = data.frame( x=runif(10), y=runif(10) ) df2 = df[order(x),] The first, as I would expect, creates a data frame with two columns and 10 rows. I expect the second to sort the data based upon the columns x and produce a new data frame, df2, with the same size as df. However, the data frame is produces is much larger. I do not understand what is going on. I am hoping somebody can help me. I am also wondering if I should have a comma after order(x) in the second statement. I do not see a purpose for it but it was in an example on the web. Thanks Bob
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, creates a data frame with two columns and > 10 rows. I expect the second to sort the data based upon > the columns x and produce a new data frame, df2, with the same size as > df. However, the data frame is produces is much larger. > I do not understand what is going on. I am hoping somebody can help me. > I am also wondering if I should have a comma after > order(x) in the second statement. I do not see a purpose for it but it > was in an example on the web. > > Thanks > Bob > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
> 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 just to prevent yet more confusion, you might also want to avoid 'df' as a name. 'df' is the function that returns the density of the F distribution ... S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}