[R] Odp: Sort a column in a dataframe

Petr PIKAL petr.pikal at precheza.cz
Tue Jul 28 14:12:58 CEST 2009


Hi

r-help-bounces at r-project.org napsal dne 28.07.2009 12:40:59:

> Dear Users
> 
> This is my dataset called mydata4. I want to sort the dataframe on the 
first
> column PxMid which is basically a column with dates.
> 
> I've tried mydata4<-mydata4[order(mydata4$PxMid),] but it doesnt work. 
Could
> it be because these are dates?

How do you know these are dates? I suspect

str(mydata4)

will have factor at PxMid and not date. If this is true, you need to 
transform it to dates by as.Date, strptime or other suitable time/date 
function e.g. fro chron package.

Regards
Petr



> Please help I'm really stuck !!
> 
> Thank you for your time.
> 
> Regards
> Meenu
> 
> PxMid EU0006MIndex.x DMSW1Curncy.x DMSW2Curncy.x DMSW3Curncy.x
> 1 01/01/2003        2.80113        2.7070        2.8920        3.1720
> 2 01/01/2007        3.85350        4.0760        4.1250        4.1230
> 3 01/02/2002        3.41563        3.6385        4.0810        4.3587
> 4 01/02/2006        2.70000        2.9545        3.1672        3.2792
> 5 01/05/2002        3.49863        3.7940        4.2300        4.4920
> 6 01/05/2006        3.03588        3.3254        3.5950        3.7380
>   DMSW4Curncy.x DMSW5Curncy.x DMSW6Curncy.x DMSW7Curncy.x DMSW8Curncy.x
> 1        3.4360        3.6640        3.8640        4.0360        4.1790
> 2        4.1230        4.1250        4.1350        4.1460        4.1620
> 3        4.5487        4.6988        4.8313        4.9338        5.0138
> 4        3.3627        3.4342        3.4899        3.5437        3.5941
> 5        4.7650        4.8675        5.0550        5.1600        5.2400
> 6        3.8290        3.9050        3.9690        4.0240        4.0750
>   DMSW9Curncy.x DMSW10Curncy.x DMSW12Curncy.x DMSW15Curncy.x 
DMSW20Curncy.x
> 1        4.2990         4.4000         4.5575         4.7175 4.8600
> 2        4.1800         4.2000         4.2330         4.2750 4.3120
> 3        5.0788         5.1263         5.2100         5.2887 5.3562
> 4        3.6457         3.6913         3.7725         3.8669 3.9410
> 5        5.3050         5.3575         5.4450         5.5425 5.6300
> 6        4.1230         4.1650         4.2360         4.3170 4.3960
>   DMSW30Curncy.x EUSA40Curncy.x EUSA50Curncy.x spread.x  level.x State1
> State2
> 1         4.8925         4.8400         4.7975   2.0005 4.006772     NA
> NA
> 2         4.2890         4.2460         4.2040   0.1640 4.165147     NA
> NA
> 3         5.3412         5.2913         5.2638   1.2602 4.792737     NA
> NA
> 4         3.9840         3.9760         3.9560   0.8168 3.550524     NA
> NA
> 5         5.6275         5.5775         5.5375   1.3975 5.007331     NA
> NA
> 6         4.4290         4.4190         4.3980   0.8340 3.998781     NA
> NA
>   State3 State4 State5 State6 State7 State8 State9
> 1     NA     NA     NA      6     NA     NA     NA
> 2     NA     NA      5     NA     NA     NA     NA
> 3     NA     NA     NA     NA     NA     NA      9
> 4     NA     NA     NA      6     NA     NA     NA
> 5     NA     NA     NA     NA     NA     NA      9
> 6     NA     NA     NA      6     NA     NA     NA
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list