-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram3.R
More file actions
38 lines (30 loc) · 971 Bytes
/
Program3.R
File metadata and controls
38 lines (30 loc) · 971 Bytes
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
#3rd program
#(a)
class(state.x77)
s77<-data.frame(state.x77)
class(s77)
#(b)
summary(s77)
nrow(s77[s77$Income<5000,])
#(c)
row.names(s77[which.max(s77$Income),])
row.names(s77[which.min(s77$Income),])
#(d)
df <- data.frame(state.abb, state.area, state.division, state.region, row.names = state.name)
colnames(df) <- substr(colnames(df), 7, 9)
new.df <- cbind(state.x77,df)
new.df
#(d)
new.df$div <- NULL
new.df <- subset(new.df[,-c(4, 6, 7, 9, 10)])
print(new.df)
#(e)
new.df$Illiteracy.Levels <- ifelse(new.df$Illiteracy >= 0 &
new.df$Illiteracy < 1,"Low",
ifelse(new.df$Illiteracy >= 1 & new.df$Illiteracy < 2, "Some","High"))
new.df$Illiteracy.Levels
# (f) Filter and find the state from the West with low illiteracy and the highest income
x <- subset(new.df, state.region == "W" & Illiteracy.Levels == "Low")
row.names(x[which.max(x$Income),])
#g
colnames(df)["state.region"] <- "reg"