I\'d like to replace all values in my relatively large R dataset which take values above the 95th and below the 5th percentile, with those percentile values
This would do it.
fun <- function(x){ quantiles <- quantile( x, c(.05, .95 ) ) x[ x < quantiles[1] ] <- quantiles[1] x[ x > quantiles[2] ] <- quantiles[2] x } fun( yourdata )