-
Notifications
You must be signed in to change notification settings - Fork 0
/
R code.R
62 lines (49 loc) · 1.67 KB
/
R code.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Set working directory in R
setwd("C:/Users/binhm/Dropbox/Biobank/Study 2--Demographics")
#Convert CSV file into data frame in R
MyData <- read.csv(file="Mycode all approached 20180917 prelim analysis.csv", header=TRUE, sep=",")
#Find % of decision by sex
library(janitor)
MyData %>%
tabyl(PT_SEX, mycode_contacts) %>%
adorn_percentages() %>%
adorn_pct_formatting()
#Convert text for race variable into all uppercase (or lowercase)
#???
#Find % of decision by race
MyData %>%
tabyl(PT_RACE, mycode_contacts) %>%
adorn_percentages() %>%
adorn_pct_formatting()
#Find % of decision by smoker status
MyData %>%
tabyl(SMOKER_FLG, mycode_contacts) %>%
adorn_percentages() %>%
adorn_pct_formatting()
#Convert 0 into nonsmoker and 1 into smoker
MyData <- Recode(c(SMOKER_FLG), old=0, new="nonsmoker")
MyData <- Recode(c(SMOKER_FLG), old=1, new="smoker")
#???
#Find % of decision by Geisinger PCP
MyData %>%
tabyl(PT_GHS_PCP_YN, mycode_contacts) %>%
adorn_percentages() %>%
adorn_pct_formatting()
#Convert 0 into No and 1 into Yes
MyData <- Recode(c(PT_GHS_PCP_YN), old=0, new="No")
MyData <- Recode(c(PT_GHS_PCP_YN), old=1, new="Yes")
#???
#Find means for BMI and CCI
library(plyr)
ddply(MyData, .(mycode_contacts), summarize, BMI=mean(BMI, na.rm = TRUE), CCI=mean(CCI, na.rm = TRUE))
#Find mean for age
#???
#Find medians for BMI and CCI
ddply(MyData, .(mycode_contacts), summarize, BMI=median(BMI, na.rm = TRUE), CCI=median(CCI, na.rm = TRUE))
#Find median for age
#???
#Code dichotomous variable Sex
d <- MyData(PT_SEX = c("Male", "Female"))
mapping <- c("Male" = 1, "Female" = 2)
d$variable.r <- mapping[d$variable]
#???