Dear All,
How can I sort a data frame with respect to more than one variable?
I know that for one variable X one may use: df[order(df$X), ] where df is
the data frame containing X.
Many thanks,
Bernard
-
[[alternative
Le 21.09.2005 10:54, Marc Bernard a écrit :
Dear All,
How can I sort a data frame with respect to more than one variable?
I know that for one variable X one may use: df[order(df$X), ] where df is
the data frame containing X.
Many thanks,
Bernard
You already know the answer of
Bernard [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Wednesday, September 21, 2005 10:54 AM
Subject: [R] Sort a data frame with respect to more than one variable
Dear All,
How can I sort a data frame with respect to more than one variable?
I know that for one variable X one may use
Marc Bernard a écrit :
I know that for one variable X one may use:
df[order(df$X), ] where df is the data frame containing X.
probably not optimal, but simply why not ?
dfX = df[order(df$X), ];
dfXY = dfX[order(dfX$Y), ];
hih
__
Hi all
I have the next data frame
year STODSLAGNR TAL TALT TALVEKT
1 2002 2120006 57 1 NA 1
2 1997 9703003257 NA NA NA
3 1997 9703007127 1 NA NA
4 1997 9703000557 1 NA NA
5 1997 9702012760 NA 1
/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message -
From: Luis Rideau Cruz [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 20, 2004 10:51 AM
Subject: [R] Sort a data frame
Hi all
I have
Hi
Lets assign your data frame to the variable yourdf
then:
yourdf[ , order( yourdf$year ) ]
should sort it.
For decreasing increasing sorting
see
?order
Sincerely Eryk.
*** REPLY SEPARATOR ***
On 20.07.2004 at 09:51 Luis Rideau Cruz wrote:
Hi all
I have the next data
Try to convert the dataframe in a matrix:
z-as.matrix(yourdataframe)
sort(z)
It would run!
Ciao
Vito
Hi all
I have the next data frame
year STODSLAGNR TAL TALT TALVEKT
1 2002 2120006 57 1 NA 1
2 1997 9703003257 NA NA NA
3 1997 97030071
hi,
i had this trouble a while ago and found this function in latest R-help.
SortMat - function(Mat, sort)
{
m - do.call(order, as.data.frame(Mat[, Sort]))
Mat[m, ]
}
where mat is a matrix and sort the column you want to be sorted.
convert you dataframe into matrix or change this
Hallo
or you can
your.df[order(your.df$year),]
Cheers
Petr
On 20 Jul 2004 at 14:35, Yves Magliulo wrote:
hi,
i had this trouble a while ago and found this function in latest
R-help. SortMat - function(Mat, sort) {
m - do.call(order, as.data.frame(Mat[, Sort]))
Mat[m, ]
Since this is such an FAQ, perhaps sort() could be made generic, with a
method for data frame? Here's a crack at it:
sort.data.frame - function(x, key, ...) {
if (missing(key)) {
rn - rownames(x)
if (all(rn %in% 1:nrow(x))) rn - as.numeric(rn)
x[order(rn, ...), ,
Liaw, Andy andy_liaw at merck.com writes:
Does anyone know how to test whether a
character can be coerced into numeric without generating a warning?
res - tryCatch(as.numeric(x), warning = function(x)x)
res is now numeric if x was successfully converted and is unchanged
if it was not. You
Gabor Grothendieck ggrothendieck at myway.com writes:
Liaw, Andy andy_liaw at merck.com writes:
Does anyone know how to test whether a
character can be coerced into numeric without generating a warning?
res - tryCatch(as.numeric(x), warning = function(x)x)
res is now numeric if x
Gabor Grothendieck wrote:
Gabor Grothendieck ggrothendieck at myway.com writes:
Liaw, Andy andy_liaw at merck.com writes:
Does anyone know how to test whether a
character can be coerced into numeric without generating a warning?
res - tryCatch(as.numeric(x), warning =
14 matches
Mail list logo