[R] Asking Favor For "Remove element with Particular Value In Vector"
Bert Gunter
gunter.berton at gene.com
Mon Aug 29 16:06:33 CEST 2011
Jim et. al:
This is the second time I've seen this "advice" recently. Use logical
indexing: which(), though not wrong, is superfluous:
x[ !x %in% c(0,255)] will do, rather than:
> If you want to remove the specific values 0 and 255 from your vector, try:
>
> x<-x[-which(x %in% c(0,255))]
>
> Jim
>
-- Bert
> ______________________________________________
> R-help at 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.
>
--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."
-- Maimonides (1135-1204)
Bert Gunter
Genentech Nonclinical Biostatistics
More information about the R-help
mailing list