[R] Filtering out bad data points

Robert A'gata rhelpacc at gmail.com
Tue May 10 02:57:00 CEST 2011


Hi,

I always have a question about how to do this best in R. I have a data
frame and a set of criteria to filter points out. My procedure is to
always locate indices of those points, check if index vector length is
greater than 0 or not and then remove them. Meaning

dftest <- data.frame(x=rnorm(100),y=rnorm(100));
qtile <- quantile(dftest$x,probs=c(0.05,0.95));
badIdx <- which((dftest$x < qtile[1]) | (dftest$x > qtile[2]));
if (length(badIdx) > 0) {
    dftest <- dftest[-idx,];
}

My question is that is there a more streamlined way to achieve this? Thank you.

Cheers,

Robert



More information about the R-help mailing list