On Sep 7, 2011, at 8:15 AM, Martin Batholdy wrote:

Hi,

I have the following data-frame:


x <- data.frame(first = c('a','c','k','b'), second = c('b','k','a','j'), third = c('f','a','h','b'))

 first second third
1     a      b     f
2     c      k     a
3     k      a     h
4     b      j     b


Now I would like to see wether there are entries that exists in all three columns.

In the example data-frame this would be true for 'a' and 'b'
(so the row-number of the element is not important).

Because of the way you constructed this data.frame, you have factors.

a.in.b <- with( x,  first[first %in% second])

a.in.b,in.c <-  a.in.b[a.in.b %in% x$third]

a.in.b.in.c
#[1] a b
#Levels: a b c k

--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to