On 20/04/15 01:44, John Sorkin wrote:


I am receiving an error message from the by function that I don't understand:
Error in tapply(response, list(x.factor, trace.factor), fun) :
   argument "trace.factor" is missing, with no default



My code follows:


summary(ipd)
  group      values            time      subjects     weaned disp
  1:55   Min.   :0.0000   Min.   :0   Min.   :115.0   1:65   2:45
  2:35   1st Qu.:0.1950   1st Qu.:1   1st Qu.:121.0   2:25   3: 5
         Median :0.3400   Median :2   Median :126.0          4:20
         Mean   :0.3479   Mean   :2   Mean   :127.6          5:20
         3rd Qu.:0.5000   3rd Qu.:3   3rd Qu.:134.0
         Max.   :0.7300   Max.   :4   Max.   :144.0
         NA's   :48
by(ipd[,c("time","subjects","values")],ipd[,"group"],interaction.plot)
Error in tapply(response, list(x.factor, trace.factor), fun) :
   argument "trace.factor" is missing, with no default

<SNIP>

The error is not from tapply(), it is from interaction.plot(). You cannot supply a dataframe to this function, you must supply the three
arguments x.factor, trace.factor and response.

You could do:

 by(ipd[,c("time","subjects","values")],ipd[,"group"],
    function(x){names(x) <- c("x.factor","trace.factor",
                              "response");
    do.call(interaction.plot,x)})


There are several other ways of organizing the syntax, but somehow you have to make the arguments to interaction.plot() explicit.

I was somewhat surprised to find that do.call() does not work with positional matching of arguments. I.e.

by(ipd[,c("time","subjects","values")],ipd[,"group"],
    function(x){do.call(interaction.plot,x)})

does *not* work. The names of "x" have to match the names of the arguments to interaction.plot().

I'm sure this makes sense .... but I don't understand it.

cheers,

Rolf Turner

--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to