RE: [R] Order with scientific notations

2004-08-26 Thread Ted Harding
On 26-Aug-04 Kevin Wang wrote:
> Hi,
> 
> If a value like 8e-04 is in a data frame, is the following behaviour
> normal?
> 
>> final.df
>   Chr P.values
>11   0.0379
>260.068
>32   0.0025
>4   138e-04
>5   14   0.0244
>63   0.0279
>74   0.1561
>85   0.9261
>97   0.0011
>10   9   0.5125
>11  10   0.2196
>12  11   0.6457
>13  18   0.9272
> 
>> final.sorted <- data.frame(final.df[order(final.df$P.values), ],
>+row.names = 1:13)
>> final.sorted
>   Chr P.values
>17   0.0011
>22   0.0025
>3   14   0.0244
>43   0.0279
>51   0.0379
>660.068
>74   0.1561
>8   10   0.2196
>99   0.5125
>10  11   0.6457
>11   5   0.9261
>12  18   0.9272
>13  138e-04
> 
> I'd think 8e-04 should be the smallest value...?  It's R 1.9.1 on 
> Windows XP if that helps.

It looks to me as though you have managed somehow to get the
"numerical" data into the dataframe as character strings, which
will be sorted alphabetically rather than numerically by 'order'.

The first clue is that if you read in a (e.g.) CSV file with your
original data as displayed above, then print it out with 'final.df',
then the value "8e-04" shows as "0.008". Sorting this DF with your
command shows "0.008" in its proper place, at the top of the list.

The next clue is that if you then assign final final.df[4,2] with

  final.df[4,2]<-"8e-04"

and then sort the DF in the same way, then "8e-04" comes out where
you found it, i.e. at the bottom of the list. This is consistent
with alphabetical sorting, since "8" follows "0" (and in any case
"e" follows ".").

So I think you should have a look at how the data got into final.df
in the first place.

Good luck,
Ted.



E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 167 1972
Date: 26-Aug-04   Time: 09:43:10
-- XFMail --

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Order with scientific notations

2004-08-25 Thread Kevin Wang
Hi,
If a value like 8e-04 is in a data frame, is the following behaviour normal?
  > final.df
 Chr P.values
  11   0.0379
  260.068
  32   0.0025
  4   138e-04
  5   14   0.0244
  63   0.0279
  74   0.1561
  85   0.9261
  97   0.0011
  10   9   0.5125
  11  10   0.2196
  12  11   0.6457
  13  18   0.9272
  > final.sorted <- data.frame(final.df[order(final.df$P.values), ],
  +row.names = 1:13)
  > final.sorted
 Chr P.values
  17   0.0011
  22   0.0025
  3   14   0.0244
  43   0.0279
  51   0.0379
  660.068
  74   0.1561
  8   10   0.2196
  99   0.5125
  10  11   0.6457
  11   5   0.9261
  12  18   0.9272
  13  138e-04
I'd think 8e-04 should be the smallest value...?  It's R 1.9.1 on 
Windows XP if that helps.

Cheers,
Kevin
--
Ko-Kang Kevin Wang
PhD Student
Centre for Mathematics and its Applications
Building 27, Room 1004
Mathematical Sciences Institute (MSI)
Australian National University
Canberra, ACT 0200
Australia
Homepage: http://wwwmaths.anu.edu.au/~wangk/
Ph (W): +61-2-6125-2431
Ph (H): +61-2-6125-7407
Ph (M): +61-40-451-8301
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html