"magic" code: example[example>threshold] <-threshold Cheers Joris
On Mon, Jun 21, 2010 at 12:34 PM, Jim Hargreaves <ja...@ipec.co.uk> wrote: > Dear List, > > I have a list of length ~1000 filled with numerics. I need to replace the > elements of this list that are above a certain numerical threshold with the > value of the threshold. > > e.g > example=list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) > threshold=5 > <magic code goes here> > example=(1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1). > > I have written a crude script that achieves this but it's very slow. Is > there a way to do this using some R function? > > Crude script: http://pastebin.com/3KSfi8nD > > ______________________________________________ > R-help@r-project.org 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. > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php ______________________________________________ R-help@r-project.org 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.