-
Notifications
You must be signed in to change notification settings - Fork 2
/
02-clean_db.R
43 lines (35 loc) · 1.07 KB
/
02-clean_db.R
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
# paquetes ----------------------------------------------------------------
library(mosaicData)
library(tidyverse)
library(skimr)
library(naniar)
library(compareGroups)
library(janitor)
library(epiR)
library(broom)
library(avallecam)
# importar ----------------------------------------------------------------
data("Whickham")
smoke <- Whickham %>% as_tibble()
smoke %>% miss_var_summary()
smoke %>% skim()
# limpieza ----------------------------------------------------------------
smoke_clean <- smoke %>%
mutate(
#desenlace
outcome_1=as.numeric(outcome),
outcome_1=outcome_1-1,
outcome_2=fct_rev(outcome),
#exposición
smoker_2=fct_rev(smoker),
#confusor
#agegrp=cut(age,breaks = c(18,44,64,Inf),include.lowest = T))
agegrp=case_when(
age %in% 18:44 ~ "18-44",
age %in% 45:64 ~ "45-64",
age > 64 ~ "65+"),
agegrp=as.factor(agegrp)
)
smoke_clean %>% compareGroups::compareGroups(~.,data = .) %>% createTable()
write_rds(smoke_clean,"data/smokeclean_20190906.rds")
write_csv(smoke_clean,"data/smokeclean_20190906.csv")