-----Original Message-----
From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk]
Sent: 5. september 2001 11:33
To: BXC (Bendix Carstensen)
Cc: Murray Jorgensen; 'Prof Brian D Ripley'; r-help at stat.math.ethz.ch
Subject: Re: [R] Bug in ftable?? (Was: Two-way tables of data, etc)
"BXC (Bendix Carstensen)" <bxc at novonordisk.com> writes:
[tp<- tapply( breaks, list( wool, tension, variant ), mean )]
tp <- as.table( tp )
ftable( tp )
But here i get:
attr( tp, "class" ) <- "table"
ftable( tp )
Error in cbind(...) : number of rows of matrices must match
(see arg 2)
Um, I don't think so.... ;-)
# But still they seem to have similar attributes (except
attributes( tb )
attributes( tp )
Is this a bug or a facility of ftable ?
It's a bug *somewhere*, not necessarily in ftable. The problem is
either that the dimname-names are not added by tapply, that neither
as.table or ftable add dummy names, or that write.ftable gags when
names are absent. (Or put differently: Are either the "table" or
"ftable" objects *required* to have named attributes??).
Actually, the fact that tapply doesn't generated named dimnames cannot
be considered the cause since
(a) as.table should work on any matrix.
(b) the second argument to tapply is not a named list in your case
One workaround is to add in the names:
ft <- ftable(tp)
names(attr(ft,"row.vars")) <- c("wool","tension")
names(attr(ft,"col.vars")) <- "variant"
ft
another is to make sure that tapply gets the names right:
list(wool=wool,tension=tension,variant=variant), mean)
variant 1 2 3 4 5
wool tension
A L 39.0 40.5 40.0 46.0 70.0
M 28.0 29.5 26.5 12.0 18.0
H 19.5 22.0 10.0 39.5 24.5
B L 31.5 29.0 29.0 27.5 24.5
M 39.0 35.0 23.5 29.0 22.5
H 17.5 18.0 20.0 22.5 13.0
or - lazy variation - abuse the fact that dataframes are lists and do
have labeled columns:
tp <- tapply( breaks, data.frame(wool,tension,variant), mean )
ftable(tp)
variant 1 2 3 4 5
wool tension
A L 39.0 40.5 40.0 46.0 70.0
M 28.0 29.5 26.5 12.0 18.0
H 19.5 22.0 10.0 39.5 24.5
B L 31.5 29.0 29.0 27.5 24.5
M 39.0 35.0 23.5 29.0 22.5
H 17.5 18.0 20.0 22.5 13.0
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph:
(+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX:
(+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-
r-help mailing list -- Read