William,

I think to convert to numeric, you might need to do something like:

as.numeric(as.character(xxxx))  ## and not just as.numeric(xxxx)

As it stands, it would appear that it is still being read as a character string.





________________________________
From: William Armstrong <William.Armstrong@noaa.gov>
To: r-help@r-project.org
Sent: Tue, June 7, 2011 10:05:37 AM
Subject: Re: [R] Sorting a data frame with values of different lengths

Also, I tried changing a line to store W as numeric:

sample_info<-c(pds_gagehandles[i],p,as.numeric(sample_W))

But it is still sorting incorrectly:

> W_table[order(W_table$as.numeric.W.),]
   pds_gagehandles.i.  p as.numeric.W.
8                mibe  8        1004.5
1                mibe  1           746
10               mibe 10           746
6                mibe  6         811.5
2                mibe  2         818.5
11               mibe 11         822.5
4                mibe  4           879
5                mibe  5           888
9                mibe  9           901
7                mibe  7         903.5
3                mibe  3         919.5
> str(W_table)
'data.frame':   11 obs. of  3 variables:
$ pds_gagehandles.i.: Factor w/ 1 level "mibe": 1 1 1 1 1 1 1 1 1 1 ...
$ p                 : chr  "1" "2" "3" "4" ...
$ as.numeric.W.     : chr  "746" "818.5" "919.5" "879" ...


--
View this message in context: 
http://r.789695.n4.nabble.com/Sorting-a-data-frame-with-values-of-different-lengths-tp3579653p3579691.html

Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.

	[[alternative HTML version deleted]]

