[R] Subsetting/modifying a symbolic formula

2009-10-21 Thread Bryan Hanson
Hello All.. Please consider the following: y - rnorm(20, mean = 10) f1 - as.factor(rep(c(A, B, B, A), 5)) f2 - as.factor(rep(c(C, D), 10)) testdata - data.frame(y, f1, f2) testFunc - function(formula, data, ...) { #mf - model.frame(formula, data) kw.res - kruskal.test(formula, data)

Re: [R] Subsetting/modifying a symbolic formula

2009-10-21 Thread Gabor Grothendieck
Here is one way: fo - y ~ f1 * f2 one.x - lapply(all.vars(fo[[3]]), function(x) { fo[[3]] - as.name(x); fo }) one.x [[1]] y ~ f1 [[2]] y ~ f2 On Wed, Oct 21, 2009 at 11:29 AM, Bryan Hanson han...@depauw.edu wrote: Hello All.. Please consider the following: y - rnorm(20, mean = 10) f1

Re: [R] Subsetting/modifying a symbolic formula

2009-10-21 Thread Bryan Hanson
Thanks Gabor, you taught me two useful things: all.vars, and the fact that a formula object always has length 3. Problem solved. Bryan On 10/21/09 11:57 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Here is one way: fo - y ~ f1 * f2 one.x - lapply(all.vars(fo[[3]]), function(x) {