-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhw1ques2.R
114 lines (99 loc) · 2.74 KB
/
hw1ques2.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
housing_data <- read.csv("housetype_data.txt", header=TRUE)
dim(housing_data)
head(housing_data, 5)
attributeHist <- function(attribute){
if(attribute=='ht'){
hist_plot <- hist(housing_data$ht)
if(sum(is.na(housing_data$ht > 0))){
mis_val <- sum(is.na(housing_data$ht))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='sex'){
hist_plot <- hist(housing_data$sex)
if(sum(is.na(housing_data$sex > 0))){
mis_val <- sum(is.na(housing_data$sex))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='age'){
hist_plot <- hist(housing_data$age)
if(sum(is.na(housing_data$age > 0))){
mis_val <- sum(is.na(housing_data$age))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='edu'){
hist_plot <- hist(housing_data$edu)
if(sum(is.na(housing_data$edu > 0))){
mis_val <- sum(is.na(housing_data$edu))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='ocu'){
hist_plot <- hist(housing_data$ocu)
if(sum(is.na(housing_data$ocu > 0))){
mis_val <- sum(is.na(housing_data$ocu))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='inc'){
hist_plot <- hist(housing_data$inc)
if(sum(is.na(housing_data$inc > 0))){
mis_val <- sum(is.na(housing_data$inc))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='ba'){
hist_plot <- hist(housing_data$ba)
if(sum(is.na(housing_data$ba > 0))){
mis_val <- sum(is.na(housing_data$ba))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='di'){
hist_plot <- hist(housing_data$di)
if(sum(is.na(housing_data$di > 0))){
mis_val <- sum(is.na(housing_data$di))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='hs'){
hist_plot <- hist(housing_data$hs)
if(sum(is.na(housing_data$hs > 0))){
mis_val <- sum(is.na(housing_data$hs))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='hs2'){
hist_plot <- hist(housing_data$hs2)
if(sum(is.na(housing_data$hs2 > 0))){
mis_val <- sum(is.na(housing_data$hs2))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='hhs'){
hist_plot <- hist(housing_data$hhs)
if(sum(is.na(housing_data$hhs > 0))){
mis_val <- sum(is.na(housing_data$hhs))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='eth'){
hist_plot <- hist(housing_data$eth)
if(sum(is.na(housing_data$eth > 0))){
mis_val <- sum(is.na(housing_data$eth))
sprintf("There are %i missing values", mis_val)
}
}
else if(attribute=='lang'){
hist_plot <- hist(housing_data$lang)
if(sum(is.na(housing_data$lang > 0))){
mis_val <- sum(is.na(housing_data$lang))
sprintf("There are %i missing values", mis_val)
}
}
else{
print("There is no such attribute.")
}
}