Hi Johannes,

You need to add the drop=FALSE argument in order to keep the structure:
df.sort <- df[order(df[,"x"]), , drop=FALSE] ## don't forget the extra comma

See ?"[" for details

HTH,
Ivan

--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calan...@u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra


Le 08/06/12 09:22, Johannes Radinger a écrit :

Hi,

I have a 1-column dataframe with rownames and I want to sort it
based on the single column. The typical procedure that is recommended
in diverse posts is to use order in the index. But that "destroys" my
dataframe structure. Probabaly it is a very simple solution. Here is a
short reproducable example:

x<- c(1,3,51,2,34,44,12,33,2,8)

df<- data.frame(x)
rownames(df)<- c("A","B","C","D","E","F","G","H","I","J")

df.sort<- df[order(df[,"x"]),]

/Johannes

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to