[R] How to get the duplicated elements from a vector?

Leon Yee yee.leon at gmail.com
Thu Oct 30 03:49:19 CET 2008


Erik Iverson wrote:
> ## BEGIN R CODE
> ## guarantees there is at least one level with exactly three elements,
> ## which your problem seems to require
> t1 <- data.frame(a = rnorm(10), b = c("D", "D", "D", 
> sample(LETTERS[1:3], 7, replace = TRUE)))
> 
> ## find which names have exactly three elements
> t2 <- subset(t1, b %in% names(which(table(t1$b) == 3)))
> 
> ## note that the elements of the returned value depend on what was
> ## originally in your data set's 'b' column
> tapply(t2$a, t2$b, mean)
> 
> ## END R CODE


Hi,

    Thank you all for the kind help. Now I've learned much and solved my 
problem with your helpful information :)

Cheers,
Leon



More information about the R-help mailing list