Re: [R] Passing parameter to a function

2010-12-20 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Luca Meyer > Sent: Monday, December 20, 2010 11:03 AM > To: Duncan Murdoch > Cc: R-help@r-project.org > Subject: Re: [R] Passing parameter to a function >

Re: [R] Passing parameter to a function

2010-12-20 Thread Bert Gunter
Duncan's solution works for me. I strongly suspect that you have not read the Help file for xtabs carefully enough. Does the "time" column in D consist of a vector of counts? > A <- factor(c("A","A","B","B")) > B <- factor(c(1,2,1,2)) > D <- data.frame(A,B) > D$time <- c(10,12,14,16) > tab(A

Re: [R] Passing parameter to a function

2010-12-20 Thread Luca Meyer
Hi Duncan, Yes, A and B are columns in D. Having said that I and trying to avoid tab(D$A,D$B) and I would prefer: tab(A,B) Unfortunately the syntax you suggest is giving me the same error: Error in eval(expr, envir, enclos) : object "A" not found I have tried to add some deparse() but I hav

Re: [R] Passing parameter to a function

2010-12-20 Thread Duncan Murdoch
On 20/12/2010 1:13 PM, Luca Meyer wrote: I am trying to pass a couple of variable names to a xtabs formula: > tab<- function(x,y){ xtabs(time~x+y, data=D) } But when I run: > tab(A,B) I get: Error in eval(expr, envir, enclos) : object "A" not found I am quite sure that there is some

[R] Passing parameter to a function

2010-12-20 Thread Luca Meyer
I am trying to pass a couple of variable names to a xtabs formula: > tab <- function(x,y){ xtabs(time~x+y, data=D) } But when I run: > tab(A,B) I get: Error in eval(expr, envir, enclos) : object "A" not found I am quite sure that there is some easy way out, but I have tried with differen