Re: [R] comparing 2 lists

From: jim holtman <jholtman_at_gmail.com>
Date: Sat 28 Oct 2006 - 18:12:56 GMT

I think you want the set operations:

> list1<-c(1,3,6,8,9)
> list2<-c(3,5,1,0)
> union(list1, list2)
[1] 1 3 6 8 9 5 0
> intersect(list1, list2)

[1] 1 3
>

On 10/28/06, Milton Cezar Ribeiro <milton_ruser@yahoo.com.br> wrote:
>
> Hi there,
>
> Could someone help to compare to list. I do something like:
>
> list1<-c(1,3,6,8,9)
> list2<-c(3,5,1,0)
> mathlist<-NULL
>
> for (i in list1) {
> for (j in list2) {
> if (i==j) mathlist<-c(mathlist,i)
> }}
> mathlist
>
> Is there a more elegant way to solve this question?
>
> Kind regards
>
> Miltinho
> BRAZIL
>
>
>
>
> ---------------------------------
> VocÍ quer respostas para suas perguntas? Ou vocÍ sabe muito e quer
> compartilhar seu conhecimento? Experimente o Yahoo! Respostas!
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]


______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.

Received on Sun Oct 29 05:18:40 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 Sat 28 Oct 2006 - 19:31:17 GMT.

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