[R] What is the R equivalent of STATA's 'drop' command?
stephen sefick
ssefick at gmail.com
Tue Feb 10 04:49:02 CET 2009
It depends on how the data is set up (I am not an expert), but I have
had good results with the subset function. subset(x, var!=3 & var!=4)
this will take the subset of the dataframe x where var is not equal
to 3 or 4.
a <- rnorm(25)
var <- rep(c(1:5), 5)
x <- data.frame(a, var)
subset(x, var!=3 & var!=4)
Is this what you want?
Stephen Sefick
On Mon, Feb 9, 2009 at 7:27 PM, jjh21 <jjharden at gmail.com> wrote:
>
> Hello,
>
> I am trying to do some data cleaning in R. I need to drop observations that
> take on certain values of a variable. In STATA I might type something like:
>
> drop if <variable name> == 3
> drop if <variable name> == 4
>
> Is there an R equivalent of this? I have tried playing around with the
> subset command, but it seems a bit clunky. What would an advanced R user's
> approach be for something like this?
>
> Thank you!
>
>
> --
> View this message in context: http://www.nabble.com/What-is-the-R-equivalent-of-STATA%27s-%27drop%27-command--tp21925249p21925249.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.
>
--
Stephen Sefick
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.
-K. Mullis
More information about the R-help
mailing list