Good evening,
I am currently having problems when creating this htmlTable file. The problem is that I would like the table to have one row with all the ages and two rows for each age group. I would love doing the same thing with the variable sex, one row for all the sexes and the p value and then one for male and another one for female. Does anybody know how to do this?
library(reprex)
#> Warning: package 'reprex' was built under R version 3.6.3
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.6.3
#> Warning: package 'ggplot2' was built under R version 3.6.3
#> Warning: package 'tibble' was built under R version 3.6.3
#> Warning: package 'tidyr' was built under R version 3.6.3
#> Warning: package 'dplyr' was built under R version 3.6.3
library(Hmisc)
#> Warning: package 'Hmisc' was built under R version 3.6.3
#> Loading required package: lattice
#> Loading required package: survival
#> Loading required package: Formula
#>
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:dplyr':
#>
#> src, summarize
#> The following objects are masked from 'package:base':
#>
#> format.pval, units
library(Gmisc)
#> Warning: package 'Gmisc' was built under R version 3.6.3
#> Loading required package: Rcpp
#> Loading required package: htmlTable
#> Warning: package 'htmlTable' was built under R version 3.6.3
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
library(rstudioapi)
#> Warning: package 'rstudioapi' was built under R version 3.6.3
library(htmlTable)
library(readr)
essai <- read_csv("C:/Users/juanp/Desktop/R4SARS/Sources/essai.csv")
#> Parsed with column specification:
#> cols(
#> Nom = col_character(),
#> Sex = col_double(),
#> Age = col_double(),
#> Death = col_double()
#> )
essai<-essai%>%mutate(Sex=factor(Sex,labels = c("Male","Female")))
essai<-essai%>%mutate(age_cat=cut(Age,c(10,20,30)))
as.vector(essai)
#> # A tibble: 13 x 5
#> Nom Sex Age Death age_cat
#> <chr> <fct> <dbl> <dbl> <fct>
#> 1 Juan Male 14 1 (10,20]
#> 2 Juan Female 21 0 (20,30]
#> 3 Maria Male 14 1 (10,20]
#> 4 Ale Female 25 1 (20,30]
#> 5 Fra Male 16 0 (10,20]
#> 6 Helena Male 21 0 (20,30]
#> 7 Roger Female 16 0 (10,20]
#> 8 Beckham Female 23 0 (20,30]
#> 9 USMLE Male 19 0 (10,20]
#> 10 Paul Male 17 0 (10,20]
#> 11 Pauline Female 15 0 (10,20]
#> 12 Selena Female 29 1 (20,30]
#> 13 Trump Female 25 0 (20,30]
getTable1Stats <- function(x, digits=1){
getDescriptionStatsBy(x,
by=essai$Death,
digits=digits,
continuous_fn = describeMedian,
useNA = "ifany",
factor_fn = describeFactors,
header_count=TRUE,
add_total_col="first",
statistics = list(continuous = getPvalKruskal,
factor = getPvalChiSq,
proportion = getPvalFisher),
NEJMstyle = TRUE)
}
Table1 <- mergeDesc("age"=getTable1Stats(essai$age_cat) )
htmlTable(Table1)
Total |
0 |
1 |
P-value |
|
---|---|---|---|---|
age |
7 (53.8%) |
5 (55.6%) |
2 (50.0%) |
1.0 |
Created on 2020-05-08 by the reprex package (v0.3.0)