The following code shows that the unlisted data frame assigns an index to
each member. When one sorts the data frame based on ULST, he in fact uses
the (implicit) indices of ULST but not the actual values! Therefore, your
guess is correct.
test.vec=data.frame(c(A,F,C))
ULST=unlist(test.vec)
I have a dataset I need to sort:
test.df-data.frame(Zone=c(Floodplain, Lake,
Shoreline),Cover=c(50,60,70))
However, I don't want it sorted ascending/descending but in an order that I
define via a vector:
sort.v-data.frame(c(Lake,Shoreline,Floodplain))
I realize I could probably just create
Hi Chipper,
Try
test.df[unlist(sort.v),]
HTH,
Jorge
On Thu, Aug 26, 2010 at 5:59 PM, chipmaney wrote:
I have a dataset I need to sort:
test.df-data.frame(Zone=c(Floodplain, Lake,
Shoreline),Cover=c(50,60,70))
However, I don't want it sorted ascending/descending but in an order that I
Here's one possibility:
sort.v-c(Lake=1,Shoreline=2,Floodplain=3)
test.df[order(sort.v[as.character(test.df$Zone)]),]
Zone Cover
2 Lake60
3 Shoreline70
1 Floodplain50
- Phil Spector
On Aug 26, 2010, at 6:10 PM, Jorge Ivan Velez wrote:
Hi Chipper,
Try
test.df[unlist(sort.v),]
That does work, and I suspect it is because data.frame converts
character vectors to factors by default. So this also works:
test.df[factor(c(Lake,Shoreline,Floodplain)), ]
But why? I must be
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of chipmaney
Sent: Thursday, August 26, 2010 3:00 PM
To: r-help@r-project.org
Subject: [R] Non-standard sorts on vectors
I have a dataset I need to sort:
test.df
6 matches
Mail list logo