Re: [R] unique deletes names - intended?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed 05 Jul 2006 - 20:04:28 EST

On Tue, 4 Jul 2006, Heinz Tuechler wrote:

> Dear All,
>
> as shown in the example, unique() deletes names of vector elements.
> Is this intended?

Yes. Think of the vector as a set: it is supposed to immaterial which of the duplicated elements is retained.

The help page says

      An object of the same type of 'x'. but if an element is equal to
      one with a smaller index, it is removed.

so it is starting with a new object, not 'x'. However, the array method works differently, so the documentation needs clarification.

> Of course, one can use indexing by !duplicated() instead.

Be careful, as you might get a method for [ and that might not do want you intended (e.g. for a time series).

> Greetings,
> Heinz
>
> ## unique deletes names
> v1 <- c(a=1, b=2, c=3, e=2, a=4)
> unique(v1) # names deleted
>
> v1[!duplicated(v1)] # names preserved
>
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status Patched
> major 2
> minor 3.1
> year 2006
> month 07
> day 01
> svn rev 38471
> language R
> version.string Version 2.3.1 Patched (2006-07-01 r38471)
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jul 05 20:26:52 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 06 Jul 2006 - 00:16:38 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.