Jim Maas
2011-Jul-06 15:35 UTC
[R] elegant way of removing NA's and selecting specific values from a data.frame
I have a data.frame "e" and would like to extract the 23rd column, remove any NA's and then remove any values >= 30. I can do it in steps such as this but have failed to figure out how to do it in a single line .... any suggestions? first <- e[,23] second <- first[!is.na(first)] third <- second[second<=30] thanks a bunch J -- Dr. Jim Maas University of East Anglia
Bert Gunter
2011-Jul-06 15:49 UTC
[R] elegant way of removing NA's and selecting specific values from a data.frame
?"&" This is basic. Please read "An Intro to R" before posting any more such questions if you have not already done so. -- Bert On Wed, Jul 6, 2011 at 8:35 AM, Jim Maas <j.maas at uea.ac.uk> wrote:> I have a data.frame "e" and would like to extract the 23rd column, remove > any NA's and then remove any values >= 30. ?I can do it in steps such as > this but have failed to figure out how to do it in a single line .... any > suggestions? > > first <- e[,23] > second <- first[!is.na(first)] > third <- second[second<=30] > > thanks a bunch > > J > > -- > Dr. Jim Maas > University of East Anglia > > ______________________________________________ > 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. >-- "Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions." -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics