Re: [R] subset using noncontiguous variables by name (not index)

2007-08-27 Thread Muenchen, Robert A (Bob)
@stat.math.ethz.ch Subject: Re: [R] subset using noncontiguous variables by name (not index) Try this: %:% - function(x, y) { +prex - gsub([0-9], , x); postx - gsub([^0-9], , x) +prey - gsub([0-9], , y); posty - gsub([^0-9], , y) +stopifnot(prex == prey) +paste(prex, seq(from

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-27 Thread Thomas Lumley
On Mon, 27 Aug 2007, Muenchen, Robert A (Bob) wrote: Gabor, That works great! I think this would be a very helpful addition to the main R distribution. Perhaps with a single colon representing numerical order (exactly as you have written it) and two colons representing the order of the

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-27 Thread Muenchen, Robert A (Bob)
Thanks for helping me see why R doesn't have the obvious! -Bob -Original Message- From: Thomas Lumley [mailto:[EMAIL PROTECTED] Sent: Monday, August 27, 2007 2:12 PM To: Muenchen, Robert A (Bob) Subject: RE: [R] subset using noncontiguous variables by name (not index) On Mon, 27

[R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread Muenchen, Robert A (Bob)
Hi All, I'm using the subset function to select a list of variables, some of which are contiguous in the data frame, and others of which are not. It works fine when I use the form: subset(mydata,select=c(x1,x3:x5,x7) ) In reality, my list is far more complex. So I would like to store it in a

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread Gabor Grothendieck
Using builtin data frame anscombe try this. First we set up a data frame anscombe.seq which has one row containing 1, 2, 3, ... . Then select out from that data frame and unlist it to get the desired index vector. anscombe.seq - replace(anscombe[1,], TRUE, seq_along(anscombe)) idx -

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread François Pinard
[Muenchen, Robert A (Bob)] I'm using the subset function to select a list of variables, some of which are contiguous in the data frame, and others of which are not. It works fine when I use the form: subset(mydata,select=c(x1,x3:x5,x7)) In reality, my list is far more complex. So I would like

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread Bert Gunter
To: Muenchen, Robert A (Bob) Cc: r-help@stat.math.ethz.ch Subject: Re: [R] subset using noncontiguous variables by name (not index) Using builtin data frame anscombe try this. First we set up a data frame anscombe.seq which has one row containing 1, 2, 3, ... . Then select out from

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread Muenchen, Robert A (Bob)
A (Bob) Cc: r-help@stat.math.ethz.ch Subject: RE: [R] subset using noncontiguous variables by name (not index) The problem is that x3:x5 does not mean what you think it means. The only reason it does the right thing in subset() is because a clever trick is used there (read the code -- it's

Re: [R] subset using noncontiguous variables by name (not index)

2007-08-26 Thread Gabor Grothendieck
, August 26, 2007 6:50 PM To: 'Gabor Grothendieck'; Muenchen, Robert A (Bob) Cc: r-help@stat.math.ethz.ch Subject: RE: [R] subset using noncontiguous variables by name (not index) The problem is that x3:x5 does not mean what you think it means. The only reason it does the right thing