Re: [R] sorting data whilst ignoring NA's

2010-03-10 Thread emwater

Thanks for these suggestions. I tried them out and I get the error message:
Error in qdata$flow : $ operator is invalid for atomic vectors

Can anyone offer further suggestions on how to extract the values from
atomic vectors? 

Thanks again
Emma
-- 
View this message in context: 
http://n4.nabble.com/sorting-data-whilst-ignoring-NA-s-tp1586277p1587108.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.


[R] sorting data whilst ignoring NA's

2010-03-09 Thread emwater

Hello,

I am very new to R and have hit my first main problem that I hope someone
can easily resolve.

I have some data that looks like this (there are 20,000 rows):

> qdata
day month yearflow
   [1,]   210 1945  NA
   [2,]   310 1945  NA
   [3,]   410 1945  NA
   [4,]   510 1945  NA
   [5,]   610 1945   2.973
   [6,]   710 1945  NA
   [7,]   810 1945  NA
   [8,]   910 1945   2.973
   [9,]  1010 1945  NA
  [10,]  1110 1945  NA
  [11,]  1210 1945  NA
  [12,]  1310 1945  NA
  [13,]  1410 1945   2.973
  [14,]  1510 1945  NA


I want to sort the data in descending order by flow but with all the NA
results sent to the bottom. I have managed to sort the data using: 

topflows <- qdata[order(-flow, na.last=TRUE),] 

But this sorts the data by flow value and then year I think giving:

 day month year   flow
 [1,]  14 3 1947 222.40
 [2,]  15 3 1947 NA
 [3,]  18 3 1947 NA
 [4,]  17 3 1947 NA
 [5,]  19 3 1947 NA
 [6,]  12 3 1947 NA
 [7,]  13 3 1947 NA
 [8,]  16 3 1947 NA
 [9,]  20 3 1947 NA
[10,]  3011 1946 106.50
[11,]  30 3 1947 105.60
[12,]  2911 1946 NA
[13,]  11 3 1947 NA
[14,]  2211 1946  99.96
[15,]  2111 1946 NA

I want my data to come out like this:
[1,] 14  3  1947  222.3
[2,] 30  11 1946 106.50
[3,] 30  3  1947  105.60
[4,] 22 11 1946  99.96 and so on...


Any help would be greatly valued. 

Thanks

Emma



-- 
View this message in context: 
http://n4.nabble.com/sorting-data-whilst-ignoring-NA-s-tp1586277p1586277.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.