s-news
[Top] [All Lists]

Re: sorting a dataframe

To: "Data Analytics Corp." <dataanalytics@earthlink.net>, <s-news@lists.biostat.wustl.edu>
Subject: Re: sorting a dataframe
From: "El Imam Hanan Attia Rizk" <hanan.elimam@umontreal.ca>
Date: Sun, 27 Jan 2008 21:46:19 -0500
References: <479D2C0C.3020507@earthlink.net>
Thread-index: AchhSlw+gbn86u3MThCANTY4q9NtuwACrsa+
Thread-topic: [S] sorting a dataframe
Hi Walt;
 
Simply data sort can be done by using  Splus icons, first select all the data 
frame, then go to data, restructure, then sort,  sort column window will 
contains option "sort by column", choose column 1&2 you will get the correct 
sort
 
In addition your script:
sort.col(SDF2, "@ALL", 1:2, ascending = T) is working very well and give me the 
following output

year month 

2007 4
2007 5
2007 6
2007 7
2007 8
2007 9
2007 10
2007 11
2007 12
2008 1
So check your data format

hope this help

Hanan Elimam
Ph.D student, Pharmaceutical Sciences
Université de Montréal
Faculté de pharmacie
Pavillon Jean-Coutu, bureau 3173
2940 Chemin de la polytechnique
Montréal, H3T 1J4
 
tél.:  514-343-6111, poste 0388
FAX: 514-343-7073

________________________________

From: s-news-owner@lists.biostat.wustl.edu on behalf of Data Analytics Corp.
Sent: Sun 2008-01-27 20:12
To: s-news@lists.biostat.wustl.edu
Subject: [S] sorting a dataframe



Hi,

I have a simple dataframe, x, of two columns:

   year  month
   2008  1
   2007  4
   2007  5
   2007  6
   2007  7
   2007  8
   2007  9
   2007  10
   2007  11
   2007  12

that I want to sort by year, then month.  Forget the fact that I could
just move the first row to the end of x to get what I want; this is just
an example.  I used

          sort.col(x, "@ALL", 1:2, ascending = T)

and got

   year month
   2007  8
   2007  9
   2007  10
   2007  11
   2007  12
   2007  4
   2007  5
   2007  6
   2007  7
   2008  1

when, of course, I should have gotten

   year  month
   2007  4
   2007  5
   2007  6
   2007  7
   2007  8
   2007  9
   2007  10
   2007  11
   2007  12
   2008  1

I also tried sort.col(x, 1:2, 1:2) and got the same result.  Why?  This
should be a simple sort.   I put the data into Excel (sorry about that)
and got the correct sort.  Why not here?

Thanks,

Walt Paczkowski

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



<Prev in Thread] Current Thread [Next in Thread>