Daren Tan
2008-Jun-25 16:19 UTC
[R] selecting values that are unique, instead of selecting unique values
unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? _________________________________________________________________ Easily edit your photos like a pro with Photo Gallery. [[alternative HTML version deleted]]
Marc Schwartz
2008-Jun-25 16:29 UTC
[R] selecting values that are unique, instead of selecting unique values
on 06/25/2008 11:19 AM Daren Tan wrote:> > unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any > method to get only 2:10 (i.e. values that are unique) ? >The easiest might be: > Vec [1] 1 2 3 4 5 6 7 8 9 10 1 > Vec[table(Vec) == 1] [1] 2 3 4 5 6 7 8 9 10 HTH, Marc Schwartz
Gabor Csardi
2008-Jun-25 16:38 UTC
[R] selecting values that are unique, instead of selecting unique values
Hmmm, this is not very good:> Vec <- c(10:1,1) > Vec[ table(Vec) == 1 ][1] 9 8 7 6 5 4 3 2 1 and these are obviously not the unique values..... This one is better: Vec [ ! duplicated(Vec) & ! duplicated(Vec, fromLast=TRUE) ] Gabor On Wed, Jun 25, 2008 at 11:29:31AM -0500, Marc Schwartz wrote:> on 06/25/2008 11:19 AM Daren Tan wrote: >> >> unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any >> method to get only 2:10 (i.e. values that are unique) ? >> > > The easiest might be: > > > Vec > [1] 1 2 3 4 5 6 7 8 9 10 1 > > > Vec[table(Vec) == 1] > [1] 2 3 4 5 6 7 8 9 10 > > HTH, > > Marc Schwartz > > ______________________________________________ > 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.-- Csardi Gabor <csardi at rmki.kfki.hu> UNIL DGM
Gabor Grothendieck
2008-Jun-25 16:50 UTC
[R] selecting values that are unique, instead of selecting unique values
On Wed, Jun 25, 2008 at 12:19 PM, Daren Tan <daren76 at hotmail.com> wrote:> > > unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? > >Try this: setdiff(x, x[duplicated(x)])
Possibly Parallel Threads
- Can R do this ?
- Any simple way to subset a vector of strings that do contain a particular substring ?
- Identifying common prefixes from a vector of words, and delete those prefixes
- counting number of "G" in "TCGGGGGACAATCGGTAACCCGTCT"
- Beautify R scripts in microsoft word