[R] Sorting a Data Frame
Robert Sherry
rsherry8 at comcast.net
Tue Jan 26 22:24:27 CET 2016
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 AM, S Ellison wrote:
>> 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}}
>
> ______________________________________________
> 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 guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list