Larry White wrote:
>
> Sorry - this must be obvious,
>
Yes, it is :-)

> I want to be able to filter data in a dataframe before analyzing it.
> For example, I'd like to plot(a,b) but only include values where b >
> 1000.
>
If a and b are vectors, then b > 1000 is another vector of logical
values.

You can use logical vectors to select pieces of other vectors, like
this:

x <- c(1, 2, 3)
y <- c(TRUE, FALSE, FALSE)
x[y]
# returns only the first element, 1

So, this plot can be done this way:

filter <- (b > 1000) # filter is a logical vector
a1 <- a[filter]
b1 <- b[filter]
# Now, a1 and b1 are, resp, a and b filtered
plot(a1, b1)

Alberto Monteiro

______________________________________________
[email protected] 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.

Reply via email to