-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_1.27.rmd
More file actions
130 lines (110 loc) · 4.87 KB
/
table_1.27.rmd
File metadata and controls
130 lines (110 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: "Untitled"
author: "Smriti karki"
date: "10/27/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
library(haven)
library(pivottabler)
library(dplyr)
library(tidyr)
library(tidyverse)
library(magrittr)
library(pagedown)
```
```{r}
adsu <- read_sas("E:/Numeric mind/adam/New_Study-master/New_Study-master/adam/adsu.sas7bdat",NULL)
col2 <- adsu %>% filter(PARAM=="History of illicit non-IV drug use") %>%
group_by(TRT01P) %>%
dplyr::count(AVALC) %>%
pivot_wider(names_from = TRT01P, values_from = n)
col2$`DTG + RPV`[is.na(col2$`DTG + RPV`)] <- 0
col2$Q2M[is.na(col2$Q2M)]<- 0
col2 <- col2 %>% mutate(Total = `DTG + RPV`+ Q2M)
col2 <- col2 %>%
mutate(dtg = paste0(round(`DTG + RPV` / sum(`DTG + RPV`) * 100), "%"))%>%
mutate(q2m = paste0(round(Q2M / sum(Q2M) * 100), "%")) %>%
mutate(total = paste0(round(Total / sum(Total) * 100), "%"))
col2$dtg <- assertive.base::parenthesise(col2$dtg)
col2$q2m <- assertive.base::parenthesise(col2$q2m)
col2$total <- assertive.base::parenthesise(col2$total)
col2 <- col2 %>%
unite("DTG + RPV", c(`DTG + RPV`,dtg),sep = " ") %>%
unite("Q2M", c(Q2M,q2m),sep = " ") %>%
unite("Total", c(Total,total),sep = " ")
col2 <- col2 %>% add_row(AVALC= "History of illicit non-IV drug use",`DTG + RPV`="",Q2M="",Total="", .before = 1,.after = NULL)
col2 <- col2 %>% add_row(AVALC="n",`DTG + RPV`="7",Q2M="90",Total="97",.before = 2)
# line2 <- data.frame("n",7,90,97)
# names(line2) <- c("AVALC","DTG + RPV","Q2M","Total")
col2 <- col2 %>% add_row(AVALC= "History of illicit IV drug use",`DTG + RPV`="",Q2M="",Total="")
col2 <- col2 %>% add_row(AVALC="n",`DTG + RPV`="7",Q2M="90",Total="97")
col3 <- adsu %>% filter(PARAM=="History of illicit IV drug use") %>%
group_by(TRT01P) %>%
dplyr::count(AVALC) %>%
pivot_wider(names_from = TRT01P, values_from = n)
col3$`DTG + RPV`[is.na(col3$`DTG + RPV`)] <- 0
col3 <- col3 %>% mutate(Total = `DTG + RPV`+ Q2M)
x <- sum(col3$`DTG + RPV`)
y <- sum(col3$Q2M)
t <- sum(col3$Total)
col3 <- col3 %>%
mutate(dtg = scales::percent(`DTG + RPV`/x)) %>%
mutate(q2m = scales::percent(Q2M/y)) %>%
mutate(total = scales::percent(Total/t))
col3$dtg <- assertive.base::parenthesise(col3$dtg)
col3$q2m <- assertive.base::parenthesise(col3$q2m)
col3$total <- assertive.base::parenthesise(col3$total)
col3 <- col3 %>%
unite("DTG + RPV", c(`DTG + RPV`,dtg),sep = " ") %>%
unite("Q2M", c(Q2M,q2m),sep = " ") %>%
unite("Total", c(Total,total),sep = " ")
col3 <- col3 %>% add_row(AVALC="Current User",`DTG + RPV`="0",Q2M="0",Total="0", .before = 2, .after = NULL)
line1<- c("History of smoking use","","","")
line2 <- c("n",7,90,97)
col3 <- col3 %>% rbind(line1)
col3 <- col3 %>% rbind(line2)
col4 <- adsu %>% filter(PARAM=="History of smoking use") %>%
group_by(TRT01P) %>%
dplyr::count(AVALC) %>%
pivot_wider(names_from = TRT01P, values_from = n)
col4$`DTG + RPV`[is.na(col4$`DTG + RPV`)] <- 0
col4 <- col4 %>% mutate(Total = `DTG + RPV`+ Q2M)
x <- sum(col4$`DTG + RPV`)
y <- sum(col4$Q2M)
col4 <- col4 %>%
mutate(dtg = scales::percent(`DTG + RPV`/x)) %>%
mutate(q2m = scales::percent(Q2M/y)) %>%
mutate(total = paste0(round(Total / sum(Total) * 100), "%"))
col4$dtg <- assertive.base::parenthesise(col4$dtg)
col4$q2m <- assertive.base::parenthesise(col4$q2m)
col4$total <- assertive.base::parenthesise(col4$total)
col4 <- col4 %>%
unite("DTG + RPV", c(`DTG + RPV`,dtg),sep = " ") %>%
unite("Q2M", c(Q2M,q2m),sep = " ") %>%
unite("Total", c(Total,total),sep = " ")
col4 <- col4[-c(1),]
col4 <- col4%>% add_row(AVALC="Former Smoker",`DTG + RPV` = "2 (29%)", Q2M = "18 (20%)", Total = "20 (21%)")
table_2 <- dplyr::bind_rows(col2, col3,col4)
library(data.table)
# table_2 <- table_2 %>%
# setnames("",
# paste0("Q2M <br/> (N = ",sum(is.numeric(table_2$Q2M)),")"),
# paste0("DTG + RPV <br/> (N = ", sum(is.numeric(table_2$`DTG + RPV`)),")"),
# paste0("Total <br/> (N = ",sum(is.numeric(table_2$Total)),")"))
table_2 <-setnames(table_2, "Q2M", "Q2M <br/> (N= 90) ")
table_2 <-setnames(table_2, "DTG + RPV", "DTG + RPV (N= 7) ")
table_2 <-setnames(table_2, "Total", "Total (N= 97) ")
title <- c("<center> Table 1.27 <br/> Summary of Substance Use at Entry </center> <br/>"=4 )
sidetitle <- c("Protocol: 209035 POLAR <br/>
Population: Intent-to-Treat Exposed <br/>"=4)
footer <- paste("<br/><br/>","smritikarki:",getwd(),toupper(format(Sys.time(),format = "%d%b%Y %H:%M")))
kableExtra::kable(table_2,align = "l",escape = F, bootstrap_options = "basic") %>%
kable_minimal(full_width = T, html_font = "Courier New") %>%
kableExtra::add_header_above(header = title,escape = F,line = F) %>%
kableExtra::add_header_above(header = sidetitle,escape = F,line = F,align = "l")
rm(list = ls())
```