This function adds the column variable name to the top of a tabyl
for a complete display of information. This makes the tabyl prettier, but renders the data.frame less useful for further manipulation.
adorn_title(dat, placement = "top", row_name, col_name)
dat | a data.frame of class |
---|---|
placement | whether the column name should be added to the top of the tabyl in an otherwise-empty row |
row_name | (optional) default behavior is to pull the row name from the attributes of the input |
col_name | (optional) default behavior is to pull the column_name from the attributes of the input |
the input tabyl, augmented with the column title. Non-tabyl inputs that are of class tbl_df
are downgraded to basic data.frames so that the title row prints correctly.
#> cyl #> am 4 6 8 #> 0 3 4 12 #> 1 8 3 2# Adding a title to a non-tabyl library(tidyr); library(dplyr) mtcars %>% group_by(gear, am) %>% summarise(avg_mpg = mean(mpg)) %>% spread(gear, avg_mpg) %>% adorn_title("top", row_name = "Gears", col_name = "Cylinders")#> Cylinders #> 1 Gears 3 4 5 #> 2 0 16.1066666666667 21.05 <NA> #> 3 1 <NA> 26.275 21.38