[R] How to ignore data
bbolker at gmail.com
Mon Dec 13 17:30:55 CET 2010
Steve Sidney <sbsidney <at> mweb.co.za> writes:
> Dear list
> I have quite a small data set in which I need to have the following
> values ignored - not used when performing an analysis but they need to
> be included later in the report that I write.
> Can anyone help with a suggestion as to how this can be accomplished
> Values to be ignored
> 0 - zero and 1 this is in addition to NA (null)
> The reason is that I need to use the log10 of the values when performing
> the calculation.
> Currently I hand massage the data set, about a 100 values, of which less
> than 5 to 10 are in this category.
> The NA values are NOT the problem
> What I was hoping was that I did not have to use a series of if and
> ifelse statements. Perhaps there is a more elegant solution.
It would help to have a more precise/reproducible example, but if
your data set (a data frame) is d, and you want to ignore cases where
the response variable x is either 0 or 1, you could say
ds <- subset(d,!x %in% c(0,1))
Some modeling functions (such as lm()), but not all of them, have
a 'subset' argument so you can provide this criterion on the fly:
lm(...,subset=(!x %in% c(0,1)))
More information about the R-help