yihui / printr

Some (magical) printing methods for knitr
https://yihui.org/printr/
118 stars 24 forks source link

Response.name for high-dimensional tables #16

Closed pbahr closed 8 years ago

pbahr commented 8 years ago

Thanks for the useful package. I'm printing a 3-dimensional table as the result of prop.table() call. In the code, as.data.table() is called for high-dimensional tables, which uses response.name= "Freq" by default. "Freq" response name is misleading in my case, but I don't think there is a way to change it.

yihui commented 8 years ago

Could you provide a minimal example?

pbahr commented 8 years ago
library(printr)

a <- c(T,F)
b <- factor(1:3)
c <- c("V", "W", "X", "Y", "Z")
d <- 1:100
df <- data.frame(cbind(a,b,c,d))

tab <-table(df$a, df$b, df$c)

tab
prop.table(tab)

"Freq" makes sense for the column name of the first table (tab), but not for the second table (prop.table). I would like to name it "Proportion", but not sure if it's possible.

yihui commented 8 years ago

OK, I see what you mean now. I provided one possible solution in the current devel version of printr, although I don't quite like the syntax:

```{r}
library(printr)

a <- c(T,F)
b <- factor(1:3)
c <- c("V", "W", "X", "Y", "Z")
d <- 1:100
df <- data.frame(cbind(a,b,c,d))

tab <-table(df$a, df$b, df$c)

tab
prop.table(tab)
pbahr commented 8 years ago

Thanks, @yihui for the workaround. That would solve it for now.