Reputation: 1491
I would like to nicely print two-way tables in R. The R base command table()
, allows you to print the two-way table but I would like something like View()
so that the outcome can better be visualised. However, when I apply View()
to table()
the outcome is no more a two-way table. Here is an example:
set.seed(1)
smoking_habits <- data.frame(gender = c(rep("M",10), rep("F",10)),
smoke = rbinom(20,1,0.3))
table(smoking_habits)
View(table(smoking_habits))
Is there a function that allows me to easily do so?
Upvotes: 0
Views: 332
Reputation: 1758
The result of table
turns into long format when converted to a data frame; this is useful for indexing. If you do not want this to happen, use unclass
:
View(unclass(table(smoking_habits)))
Upvotes: 2