Re: [R] newbie question

From: Alberto Vieira Ferreira Monteiro <>
Date: Sat 21 Oct 2006 - 15:29:19 GMT

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)
# 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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun Oct 22 04:10:43 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 21 Oct 2006 - 18:30:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.