[R] sorting data whilst ignoring NA's

William Dunlap wdunlap at tibco.com
Wed Mar 10 20:47:59 CET 2010


Peter's suggestion
  qdata[order(qdata$flow, decreasing=TRUE), ] 
would work if qdata were a data.frame, where the
$column syntax picks out a column.  You probably
have a matrix so use [,"flow"] instead of $flow
to extract the column called "flow".
  qdata[order(qdata[,"flow"], decreasing=TRUE), ]
(Both syntaxes work for data.frames, but only
the latter works for matrices.)

Showing the result of print(dataset) is
not sufficient to show helpers what you have.
Data.frames and matrices, both being 2 dimensional
datasets, have a similar printouts.  A printout
that looks like 2010-03-10 might represent
a Date object, a POSIXlt object, a single string,
the level of a factor, an arithmetic expression, etc. 

The output of dput(dataset) will spell out those details
and we can copy and paste it into an R session
to recreate your dataset, as it exists in your
R session.  If dput's output is too big, trim your
dataset down to something that still demonstrates
the problem but will fit in the mail.

If trimming it down makes the problem disappear,
showing the output of str(dataset) would be
helpful: it tells us about the dataset's structure
but, unlike dput, it makes us think about how to
recreate the object that gave you trouble.

You can also show the commands used to make the
the problematic dataset.  Make sure they don't
involve reading some file that is not on our
computers.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of emwater
> Sent: Wednesday, March 10, 2010 1:07 AM
> To: r-help at r-project.org
> Subject: Re: [R] sorting data whilst ignoring NA's
> 
> 
> 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-tp15862
77p1587108.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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