[R] newbie question
Alberto Vieira Ferreira Monteiro
albmont at centroin.com.br
Sat Oct 21 17:29:19 CEST 2006
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
More information about the R-help
mailing list