And once you have all your variables of interest in a list, you can avoid the explicit loop by using the Reduce function (which works for cases where you have a function that takes 2 arguments and you want to apply it recursively to more than 2):
> tmp <- list( a=1:10, b=5:15, c=20 ) > Reduce( union, tmp ) [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 20 > Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] 801.408.8111 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Wacek Kusnierczyk > Sent: Friday, October 17, 2008 5:46 AM > To: Leon Yee > Cc: R help > Subject: Re: [R] A question about "union" > > Leon Yee wrote: > > But the problem is that I have MANY vectors, whose names are of some > > specific pattern. It is not good for us to write a very long > expression. > > > > vectors <- list(ls(pattern="xyz")) didn't get what I want. > > then you could mix the two approaches: > > vectors = lapply(ls(pattern="xyz"), get) > > u = NULL > for (v in vectors) ... > > which version is better will of course depend on the particular context > of your problem. > > vQ > > ______________________________________________ > 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. ______________________________________________ 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.