Gabor Grothendieck wrote:
> DF <- data.frame(a = c(3, 4, 2, 3, 2, 4, 2), b = 7:1))
> DF[do.call(order, DF),]
>
> will sort on all the columns.
... and you can use
DF[do.call(order, DF[names]),]
if you have the column names in a character vector.
>
> On 11/28/06, michael watson (IAH-C) <[EMAIL P
Thanks guys, sorted now :)
From: Peter Dalgaard [mailto:[EMAIL PROTECTED]
Sent: Tue 28/11/2006 11:05 AM
To: Gabor Grothendieck
Cc: michael watson (IAH-C); r-help@stat.math.ethz.ch
Subject: Re: [R] Sorting a data frame when you don't know the columns
" <[EMAIL PROTECTED]>
To:
Sent: Tuesday, November 28, 2006 11:45 AM
Subject: [R] Sorting a data frame when you don't know the columns
> Hi
>
> Sorry to ask such a well oiled question, but even with multiple
> google hits I don't think this has been answered very
DF <- data.frame(a = c(3, 4, 2, 3, 2, 4, 2), b = 7:1))
DF[do.call(order, DF),]
will sort on all the columns.
On 11/28/06, michael watson (IAH-C) <[EMAIL PROTECTED]> wrote:
> Hi
>
> Sorry to ask such a well oiled question, but even with multiple google hits I
> don't think this has been answered
Hi
Sorry to ask such a well oiled question, but even with multiple google hits I
don't think this has been answered very well.
It's all well and good doing a sort of a data frame on multiple columns when
you know in advance which columns you want to sort on, but what about when the
names of
Leaf,
using your example data as 'dat' below --
dat<-read.table("clipboard",header=T)
dat
XYZ
1 22.0 24.0 4.3
2 2.3 3.4 5.3
3 57.2 23.4 34.0
#to order the data frame by say X (for column 1)--
dat1<-dat[order(dat[,1]),]
dat1
XYZ
2 2.3 3.4 5.3
1 22.0 24.0 4.3
FAQ 7.23 How can I sort the rows of a data frame?
To sort the rows within a data frame, with respect to the values in one or more
of the columns, simply use order().
=== 2005-10-16 13:29:44 您在来信中写道:===
>
>Dear all,
>
>I have a date frame like this:
>
>X Y Z
>22 24
Try
RSiteSearch("sort data.frame")
?order
RSiteSearch("sort.data.frame")
On 10/16/05, Leaf Sun <[EMAIL PROTECTED]> wrote:
>
> Dear all,
>
> I have a date frame like this:
>
> X Y Z
> 22 24 4.3
> 2.3 3.4 5.3
> .
>
> 57.223.434
>
> What my purpose is: to sort
Dear all,
I have a date frame like this:
X Y Z
22 24 4.3
2.3 3.4 5.3
.
57.223.434
What my purpose is: to sort the data frame by either X, Y or Z.
sample output is (sorted by X) :
X Y Z
2.3 3.4 5.3
.
..
22 24 4.3
...
57.2 23.4 34
I have n
On Thu, 31 Jul 2003, BORGULYA Gábor wrote:
> I think this is an important example! Is there a way to make it included
> in the help of order?
Please explain why it adds to what is already there, which looks very
similar to me.
> Maybe a shortened version:
>
> # sorting a data frame
> df <- da
Hi!
I think this is an important example! Is there a way to make it included
in the help of order?
Maybe a shortened version:
# sorting a data frame
df <- data.frame(V1 = c("W","A", "A", "B", ""), V2 = c("E", "M", "B",
"O", "Q"))
sorted <- df[order(df$V1, df$V2), ]
And a question: what to do
On Wed, 2003-07-16 at 08:42, Wayne Jones wrote:
> Hi there R-Helpers,
>
> Does anyone know if it is possible to sort a dataframe?
>
> I.e. Sort alphabetically column 1 ( which has some reocurring elements) then
> sort alphabetically column2 but keeping the order of column 1 constant;
> much the
On Wed, 16 Jul 2003 14:42:09 +0100, Wayne Jones <[EMAIL PROTECTED]>
wrote :
>
>Hi there R-Helpers,
>
>Does anyone know if it is possible to sort a dataframe?
>
>I.e. Sort alphabetically column 1 ( which has some reocurring elements) then
>sort alphabetically column2 but keeping the order of colum
?order
hope this helps. spencer graves
Wayne Jones wrote:
Hi there R-Helpers,
Does anyone know if it is possible to sort a dataframe?
I.e. Sort alphabetically column 1 ( which has some reocurring elements) then
sort alphabetically column2 but keeping the order of column 1 constant;
much the
Hi there R-Helpers,
Does anyone know if it is possible to sort a dataframe?
I.e. Sort alphabetically column 1 ( which has some reocurring elements) then
sort alphabetically column2 but keeping the order of column 1 constant;
much the same way that the sort function works in Excel.
Regards,
15 matches
Mail list logo