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? ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Retrieve-distinct-values-within-a-whole-data-frame-tp1460205p1460205.html Sent from the R help mailing list archive at Nabble.com.
Steve Lianoglou
2010-Feb-02 18:27 UTC
[R] Retrieve distinct values within a whole data frame
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
ok it worked so the key is unlist() from what I see :working: ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Retrieve-distinct-values-within-a-whole-data-frame-tp1460205p1460217.html Sent from the R help mailing list archive at Nabble.com.