forked from cambiotraining/r-intermediate
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathfix_state.R
More file actions
21 lines (14 loc) · 748 Bytes
/
fix_state.R
File metadata and controls
21 lines (14 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
library(tidyverse)
pat <- read.delim("patient-data.txt", stringsAsFactors=FALSE)
states <- c("Californa", "California", "Colorado ", "Colorado", "Georgia", "Georgia",
"Indiana", "indiana", "New York", "New York", "New Jersey", "New Jersey")
pat$State <- sample(states, nrow(pat), replace = TRUE)
patcl <- read.delim("patient-data-cleaned.txt", stringsAsFactors=FALSE)
all(pat$ID==patcl$ID)
# [1] TRUE
patcl$State <- pat$State %>%
str_replace("Californa", "California") %>%
str_replace("Colorado ", "Colorado") %>%
str_replace("indiana", "Indiana")
write.table(pat, "patient-data.txt", row.names=FALSE, quote=FALSE, sep="\t")
write.table(patcl, "patient-data-cleaned.txt", row.names=FALSE, quote=FALSE, sep="\t")