[R] arguments must have same length

787 views
Skip to first unread message

suntime

unread,
May 11, 2012, 4:56:40 AM5/11/12
to r-h...@r-project.org
> score<-read.csv("http://users.stat.umn.edu/~chen2285/hw/ACT.csv")

> interaction.plot(sex,rep(1,861),score,fun=mean,legend=F,main="profile of
> sex")
Error: tapply(response, list(x.factor, trace.factor), fun) :
arguments must have same length

> length(sex)
[1] 861
> length(type)
[1] 861
> length(score)
[1] 3

How can I alter the length of the variable score here to make this function
work?
or any other way to perform interaction plot?


--
View this message in context: http://r.789695.n4.nabble.com/arguments-must-have-same-length-tp4625885.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-h...@r-project.org mailing list
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.

Petr PIKAL

unread,
May 11, 2012, 8:12:03 AM5/11/12
to suntime, r-h...@r-project.org
Hi
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : unable to connect to 'users.stat.umn.edu' on port
80.
>

Unable to read data.

>
> > interaction.plot(sex,rep(1,861),score,fun=mean,legend=F,main="profile
of
> > sex")
> Error: tapply(response, list(x.factor, trace.factor), fun) :
> arguments must have same length

However you are not telling us whole story. score shall be data frame and
length(data.frame) results in number of columns.

>From help page

x.factor a factor whose levels will form the x axis.
trace.factor another factor whose levels will form the traces.
response a numeric variable giving the response

your second variable to interaction plot is numeric - shall be factor
your third variable is probably data frame, shall be numeric.

It is advisable to give to functions values they expect. Some functions
can crunch unexpected data but the results can be misleading if not wrong.

Regards
Petr
Reply all
Reply to author
Forward
0 new messages