On 12/3/2008 6:32 AM, SOUVIK BANDYOPADHYAY wrote:> R Gurus,I have a vector of nearly 90,000 characters from which I have to
> extract the index of the characters which are repeated. So suppose if
>
x<-c("a","a","b","a","b","c","d")
then my output would be a vector having
> the index where the values are repeated i.e (1,2,3,4,5). I have been able
to
> isolate out the values that are repeated from the unique list of characters
> in x (i.e. y<-c("a","b")). One method can be to use
a loop on the which
> function but that would be too time consuming. Any hint on using the apply
> function effectively would be useful
> Thanks and Regards
x <-
c("a","a","b","a","b","c","d")
duplicated(x)
[1] FALSE TRUE FALSE TRUE TRUE FALSE FALSE
x %in% x[duplicated(x)]
[1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE
which(x %in% x[duplicated(x)])
[1] 1 2 3 4 5
?duplicated
> Souvik Bandyopadhyay
> Lecturer,
> Dept of Biostatistics,
> Indian Institute of Public Health,
> Hyderabad
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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