[R] Retrieve distinct values within a whole data frame

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Feb 2 19:27:12 CET 2010


Hi,

On Tue, Feb 2, 2010 at 1:19 PM, anna <lippelanna24 at hotmail.com> wrote:
>
> Hello everyone,
> I am trying to retrieve the list of distinct values within a whole data
> frame. I tried to use unique() function but it retrieves the distinct values
> within each column or row, I want it for the entire data frame, any idea?

Here's one way:

R> df <- data.frame(a=c(1,2,3,4,3,2), b=c(4,5,6,6,4,3))
R> unique(unlist(df))
[1] 1 2 3 4 5 6

I guess funny things might happen when the columns of your data.frame
are of different types, though ...

-steve
-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list