[R] Exclusion of elements in a vector
Chuck Cleland
ccleland at optonline.net
Thu Sep 25 15:15:42 CEST 2008
On 9/25/2008 7:43 AM, Stefan Fritsch wrote:
> Dear R Users,
>
> I want to exclude elements in a vector by:
>
> vector[-exclude]
>
> is it intended to cause an error if no elements are excluded?
>
>> vector <- 1:10
>> exclude <- NULL
>> vector[-exclude]
> Error in -exclude
>
> or am I just definig exclude wrong, if no elements should be excluded?
One approach would be to set "exclude" to a number greater than the
length of the vector:
x <- 1:10
exclude <- length(x) + 1
x[-exclude]
[1] 1 2 3 4 5 6 7 8 9 10
library(fortunes)
fortune("dog")
Firstly, don't call your matrix 'matrix'. Would you call your dog 'dog'?
Anyway, it might clash with the function 'matrix'.
-- Barry Rowlingson
R-help (October 2004)
> with kind regards,
>
> Stefan Fritsch
>
> ______________________________________________
> 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.
--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list