2013-11-23 29 views

回答

1

從一些代碼以從你鏈接的問題:

# @aL3xa's function 
remove_outliers <- function(x, na.rm = TRUE, ...) { 
    qnt <- quantile(x, probs=c(.25, .75), na.rm = na.rm, ...) 
    H <- 1.5 * IQR(x, na.rm = na.rm) 
    y <- x 
    y[x < (qnt[1] - H)] <- NA 
    y[x > (qnt[2] + H)] <- NA 
    y 
} 

set.seed(1) 
x <- as.data.frame(matrix(rnorm(10000),ncol=100)) # 100 x 100 data frame 
y <- remove_outliers(x[,2]) # look for outliers in columns 2 

newx<-cbind(x,y) 

newx2<-x[!is.na(x$y),] 
相關問題