-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCocke_HW5.R
41 lines (24 loc) · 1.07 KB
/
SCocke_HW5.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
##Problem 1
df <- data.frame(read.delim("/Users/stevencocke/Downloads/Download-22/yob2016 (1).txt", sep=";", header = FALSE))
names(df) <- c("Name", "Gender", "NumberofChildren")
summary(df)
srt(df)
grep("yyy$",df$Name)
df[212,]
y2016 <- df[-212,]
grep("yyy$", y2016$Name)
##Problem 2
y2015 <- data.frame(read.delim("/Users/stevencocke/Downloads/Download-22/yob2015 (1).txt", sep=",", header = FALSE))
names(y2015) <- c("Name", "Gender", "NumberofChildren")
##The bottom 10 Names all appear 5 times in 2015, and the last two Zyrus and Zyus could be a mispelling
tail(y2015, 10)
final <- merge(y2016,y2015,by="Name", na.rm=TRUE)
##Problem 3
Total <- final$NumberofChildren.x + final$NumberofChildren.y
final <- cbind(final, Total)
final <- final[order(-Total),]
head(final,10)
head(final[!(final$Gender.x=="M" & final$Gender.y=="M"),],10)
top10girls <- head(final[!(final$Gender.x=="M" & final$Gender.y=="M"),],10)
top10girls <- subset(top10girls, select = -c(Gender.y, Gender.x, NumberofChildren.x, NumberofChildren.y))
write.csv(top10girls, 'top10girls.csv',row.names = FALSE)