[Rd] Subset of a 'table' divided by a 'table' is a 'table', but printed by 'print.default'

Suharto Anggono Suharto Anggono suharto_anggono at yahoo.com
Tue Apr 30 09:38:45 CEST 2013


This is just info.

I recently got something like this.

> x <- factor(c("A","A","B","B"), levels=c("A","B"))
> y <- factor(c("a","b","a","b"), levels=c("a","b"))
> table(x, y)[, "a"] / table(x)
x
  A   B
0.5 0.5
attr(,"class")
[1] "table"

The printing indicates that the result is of class 'table'. But, the 'print' method of class 'table' does not print attr(,"class"). It seems that 'print.default' is used in the printing. I am OK with it, just unusual.

I think, that is another symptom of an already known behavior as in the following:
- PR#2345: difftime arithmetic
- PR#13209: S4 object does not commute?


> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



More information about the R-devel mailing list