Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-15 Thread peter dalgaard
On Jul 15, 2011, at 15:06 , peter dalgaard wrote: > For a little lateral thinking, consider the use of "." on the LHS. That could > play out as follows: > >> myvars <- c("Ozone","Wind") >> f <- . ~ Month >> j <- union(all.vars(f[[3]]), myvars) >> aggregate(. ~ Month, data=airquality[j], mean, n

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-15 Thread Dimitri Liakhovitski
f Of Dimitri Liakhovitski > Sent: Thursday, July 14, 2011 1:45 PM > To: David Winsemius > Cc: r-help > Subject: Re: [R] cbind in aggregate formula - based on an existing object > (vector) > > Thanks a lot! > > actually, what I tried to do is very simple - just passing tons

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-15 Thread peter dalgaard
For a little lateral thinking, consider the use of "." on the LHS. That could play out as follows: > myvars <- c("Ozone","Wind") > f <- . ~ Month > j <- union(all.vars(f[[3]]), myvars) > aggregate(. ~ Month, data=airquality[j], mean, na.rm=T) MonthOzone Wind 1 5 23.61538 11.457692

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Dennis Murphy
Hi: I think Bill's got the right idea for your problem, but for the fun of it, here's how Bert's suggestion would play out: # Kind of works, but only for the first variable in myvars... > aggregate(get(myvars) ~ group + mydate, FUN = sum, data = example) group mydate get(myvars) 1 group1 2

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread William Dunlap
iakhovitski Sent: Thursday, July 14, 2011 1:45 PM To: David Winsemius Cc: r-help Subject: Re: [R] cbind in aggregate formula - based on an existing object (vector) Thanks a lot! actually, what I tried to do is very simple - just passing tons of variable names into the formula. Maybe that "

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Dimitri Liakhovitski
David - I tried exactly the thing you did (and after that asked my question to the forum): > form <- as.formula(paste( > "cbind(", > paste( myvars, collapse=","), > ") ~ group+mydate", > sep=" ") ) And it did not wo

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Dimitri Liakhovitski
Thanks a lot! actually, what I tried to do is very simple - just passing tons of variable names into the formula. Maybe that "get" thing suggested by Bert would work... Dimitri On Thu, Jul 14, 2011 at 4:01 PM, David Winsemius wrote: > Dmitri: > > as.matrix makes a matrix out of the dataframe t

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread David Winsemius
Dmitri: as.matrix makes a matrix out of the dataframe that is passed to it. As a further note I attempted and failed for reasons that are unclear to me to construct a formula that would (I hoped) preserve the column names which are being mangle in the posted effort: form <- as.formula(past

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Bert Gunter
Dmitri: Look at my vars from myvars<-c("value1","value2") It's just a character vector of length 2! You can't cbind a character vector of length 2! These are not references/pointers. It's not at all clear to me what you ultimately want to do, but IF it's: pass a character vector of names to be u

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Dimitri Liakhovitski
Thank you, David, it does work. Could you please explain why? What exactly does changing it to "as matrix" do? Thank you! Dimitri On Thu, Jul 14, 2011 at 3:25 PM, David Winsemius wrote: > > On Jul 14, 2011, at 3:05 PM, Dimitri Liakhovitski wrote: > >> Hello! >> >> I am aggregating using a formula

Re: [R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread David Winsemius
On Jul 14, 2011, at 3:05 PM, Dimitri Liakhovitski wrote: Hello! I am aggregating using a formula in aggregate - of the type: aggregate(cbind(var1,var2,var3)~factor1+factor2,sum,data=mydata) However, I actually have an object (vector of my variables to be aggregated): myvars<-c("var1","var2

[R] cbind in aggregate formula - based on an existing object (vector)

2011-07-14 Thread Dimitri Liakhovitski
Hello! I am aggregating using a formula in aggregate - of the type: aggregate(cbind(var1,var2,var3)~factor1+factor2,sum,data=mydata) However, I actually have an object (vector of my variables to be aggregated): myvars<-c("var1","var2","var3") I'd like my aggregate formula (its "cbind" part) to b