-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab 3.r
More file actions
32 lines (26 loc) · 960 Bytes
/
Lab 3.r
File metadata and controls
32 lines (26 loc) · 960 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
read.csv("classnames.csv")
read.csv("classnames.csv")
babynames = null
babynames = NULL
years = seq(1880,2014)
print(years)
babynames=NULL
for(i in years) {
a = as.data.frame(read.csv(paste("yob", toString(i), ".txt", sep=''), header = FALSE, col.names = c("Name", "Gender", "Count")))
b = cbind(a, i)
babynames = rbind(babynames, b)
}
a = (which(babynames$Name=="Vinit"))
Year = babynames[a,4]
Count = babynames[a,3]
plot(Year, Count)
title("Number of babies named Vinit")
female = babynames[which(babynames$Gender=="F"),]
girlnamecount = as.data.frame(table(female$i))
names(girlnamecount) = c("year", "namecounts")
plot(girlnamecount$year, girlnamecount$namecounts, xlab="Year", ylab="Number of unique girl names", main="Growth in number of unique girl names")
top_names = function(year, gender) {
pho = babynames[which(babynames$Gender==gender&babynames$i==year),]
ttn = pho[order(pho$count, decreasing = TRUE),]
return(ttn[(1:10),])
}