You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When converting an etable to a huxtable duplicate cells are left empty. In the below example the same value appears in a cross table twice and the second cell is left empty after the conversion to a huxtable (in the below example this is Male, Past Smoker). Apparently, the attempts to remove duplicate labels are a bit too aggressive, deleting some table contents in specific situations like these?
library(tidyverse, warn.conflicts=FALSE)
library(expss, warn.conflicts=FALSE)
#> Loading required package: maditr#> #> To aggregate several columns with one summary: take(mtcars, mpg, hp, fun = mean, by = am)#> #> Attaching package: 'maditr'#> The following objects are masked from 'package:dplyr':#> #> between, coalesce, first, last#> The following object is masked from 'package:purrr':#> #> transpose#> The following object is masked from 'package:readr':#> #> cols#> #> Use 'expss_output_viewer()' to display tables in the RStudio Viewer.#> To return to the console output, use 'expss_output_default()'.
library(huxtable, warn.conflicts=FALSE)
# Create some example data with equal observed frequencies in one columndata<-data.frame(
"Male"= c(14, 14, 16),
"Female"= c(12, 14, 19),
row.names= c("Never smoked", "Past smoker", "Current smoker"),
stringsAsFactors=FALSE)
# colnames(data) <- c("Male", "Female")x<- c()
for (rowin rownames(data)) {
for (colin colnames(data)) {
x<- rbind(x, matrix(rep(c(row, col), data[row, col]), ncol=2, byrow=TRUE))
}
}
df<- as.data.frame(x)
colnames(df) <- c("Smoking", "Gender") #row, column# Create etabletable<-df|>
tab_cells(`Smoking`=Smoking) |>
tab_cols(`Gender`=Gender, total(Gender)) |>
tab_total_label("Total") |>
tab_stat_cpct() |>
tab_pivot() |>
drop_empty_rows() |>
drop_empty_columns()
table
Gender
#Total
Female
Male
Smoking
Current smoker
42.2
36.4
39.3
Never smoked
26.7
31.8
29.2
Past smoker
31.1
31.8
31.5
#Total
45
44
89
# Transform into huxtablehuxtable<- as_huxtable(table)
print(huxtable)
#> Gender #Total #> Female Male #> Smoking Current 42.2 36.4 39.3 #> smoker #> Never smoked 26.7 31.8 29.2 #> Past smoker 31.1 31.5 #> #Total 45 44 89 #> #> Column names: V1, V2, V3, V4, V5
When converting an etable to a huxtable duplicate cells are left empty. In the below example the same value appears in a cross table twice and the second cell is left empty after the conversion to a huxtable (in the below example this is Male, Past Smoker). Apparently, the attempts to remove duplicate labels are a bit too aggressive, deleting some table contents in specific situations like these?
Created on 2023-02-23 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: