[R] newbie question

Paul Hiemstra p.hiemstra at geo.uu.nl
Sat Oct 21 15:55:55 CEST 2006


Dear Larry,

Data can be filtered in the following manner:

a = c(1,2,3,4)
b = c(1,2,3,4)
b = b[a>3]
b = b[b>3]
a
b
[1] 4

Or if the data is in a data frame:

b = data.frame(seq(1:10),seq(1:10)
names(b) = c("a","b")
b
b = b[b$a > 5,]
b

The trailing comma at the end is important.

Hopes this helps,

Paul





Larry White schreef:
> Sorry - this must be obvious, but i haven't been able to find the
> answer in the guides i've searched.  The examples seem to assume you
> always want to look at all the data.
>
> 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.
>
> I'd also like to be able to do similar filtering before doing other
> statistical functions.
>
> Thanks for your help.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list