-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem_01_Plotting.R
118 lines (68 loc) · 2.98 KB
/
Problem_01_Plotting.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
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
getwd()
#"C:/Users/corma/OneDrive/Documents/R/Assignment3"
browseVignettes("data.table")
browseVignettes("dplyr")
library(dplyr)
library(data.table)
library(naniar)
library(styler)
?fread
outcomes <- fread("C:/Users/corma/OneDrive/Documents/R/Assignment3/hospitaldata/outcomes.csv",
header = TRUE, sep = ",", stringsAsFactors = FALSE,
na.strings = "Not Available")
head(outcomes)
is.na(outcomes[4,11])
is.na(outcomes[4,4])
outcomes[4,11]
class(outcomes)
outcomes2 <- fread("C:/Users/corma/OneDrive/Documents/R/Assignment3/hospitaldata/outcomes.csv",
header = TRUE, stringsAsFactors = FALSE,
na.strings = "Not Available")
install.packages("naniar")
library(naniar)
na_strings <- c("Not Available")
outcomes_cleaned <- outcomes %>%
replace_with_na_all(condition = ~.x %in% na_strings)
outcomes3 <- outcomes2 <- fread("C:/Users/corma/OneDrive/Documents/R/Assignment3/hospitaldata/outcomes.csv",
stringsAsFactors = FALSE, sep = ",",
na.strings = "Not Available")
str(outcomes_cleaned)
rm(outcomes2, outcomes3)
outcomes_cleaned[, 11] <- as.numeric(outcomes_cleaned[, 11])
class(outcomes_cleaned)
class(outcomes)
#### FULL SOLUTION STARTS HERE####
library(data.table)
library(dplyr)
library(naniar)
#Trying to get the columns classified as numeric in the fread function.
outcomes <- fread("C:/Users/corma/OneDrive/Documents/R/Assignment3/hospitaldata/outcomes.csv",
header = TRUE, sep = ",", stringsAsFactors = FALSE,
colClasses=list(numeric=11))
# And failing.... moving on anyway.
na_strings <- c("Not Available")
outcomes_cleaned <- outcomes %>%
replace_with_na_all(condition = ~.x %in% na_strings)
#Weird error message - Attempt to override column 11 <<Hospital 30-Day Death
#(Mortality) Rates from Heart Attack>> of inherent type 'string' down to 'float64' ignored.
#Only overrides to a higher type are currently supported. If this was intended,
#please coerce to the lower type afterwards.
outcomes_cleaned[, 11] <- as.numeric(unlist(outcomes_cleaned[, 11]))
# Here's our plot of the 30-day mortality rates for heart attack, finally.
# This should've taken like 5 minutes lol.
hist(unlist(outcomes_cleaned[,11]), main = "Distribution of 30 Day Mortality Rates for Heart Attack
Across US Hospitals",
xlab = "30 Day Mortality Rates for Heart Attack", ylab = "Number of Hospitals")
### Testing something - delete if it doesn't work...
rm(outcomes_cleaned)
outcomes_cleaned <- as.numeric(unlist(outcomes_cleaned[,11]))
#Okay, if you set the left side of the assignment to just outcomes_cleaned and
# NOT outcomes_cleaned[, 11], you just get the vector of column 11. We don't want that!
# Everything below is BS
str(outcomes_cleaned)
variable11 <- as.numeric(unlist(outcomes_cleaned[, 11]))
hist(variable11)
is.numeric(outcomes_cleaned[,11])
class(outcomes_cleaned[,11])
typeof(outcomes_cleaned[,11])
# Testing