Introduction

The avages package includes functions which quickly offer information pertaining to the ages of the professors and lecturers at Williams College in Williamstown, MA in each year from 2004 to 2014. More specifically, avages gives, for each year, the average age of professors and lecturers, the name(s) and age(s) of the youngest and oldest professor(s) and lecturer(s), and a visual display of the distribution of ages. Additionally, avages gives a graphical representation of the change in mean ages from 2004 to 2014.

Background

Avages' functions all rely on information about faculty posted by Williams College in its annual Course Catalog (which can be found at http://web.williams.edu/admin/registrar//catalog/archive.html). The avages package contains copies of this information for each year from 2004 to 2014, which is stored as plain text files in avages' inst/extdata directory. Avages' main functions (avg_age, age_hist, oldst, yngst, and age_change) rely on the actions of two subsidiary functions (ages_1 and ages_2) which parse the text from the Course Catalogs and create a vector of ages for each year from 2004 to 2013 and for 2014, respectively. Avages determines ages operating under the assumption that, on average, professors and lecturers received their undergraduate degrees at age 22. For years 2004 through 2014, Williams posted the year an undergradduate degree was obtained for the vast majority of faculty members, but excluded this information for a handful of faculty. Avages' functions ignore this handful of faculty in their calculations. Williams College did not publish the years that factulty received degrees in the 2015 Course Catalog, so avages does not consider 2015.

Subsidiary Functions

From 2004 to 2013, Williams used the same format for posting information about its professors in the Course Catalog (i.e. "Daniel P. Aalberts Associate Professor of Physics B.S. (1989) M.I.T.; Ph.D. (1994) M.I.T."). Therefore, the same code effectively parses the 2004-2013 catalogs. For 2014, however, Williams changed the style of the facutly information section of the Course Catalog (to "Daniel P. Aalberts, Professor of Physics, 1989, BS, MA Institute of Technology, 1994, PHD, MA Institute of Technology"). Because the 2014 catalog reports the year in which the undergraduate degree was obtained before the title of the degree (rather than after, as in the 2004 through 2013 Course Catalogs), different code is required to parse the 2014 catalog.

The ages_1 function scans the plain text file pertaining to a given year from 2004 to 2013, identifies the positions of undergradduate degree titles by searching for phrases like "BA" and "BS," identifies the positions of years in which undergraduate degrees were obtained (based on the fact that in these Course Catalogs, the year a degree was obtained always appears one word after the degree title), extracts these years into a new vector, converts the years from strings to integers, and then creates a vector of ages (assuming that, on average, undergraduate degrees were obtained at age 22).

The ages_2 function does basically the exact same thing. The differences are that ages_2 only scans the plain text file containing professor information for 2014 and that it finds the years undergraduate degrees were obtained based on the fact that in the 2014 Course Catalog, the year a degree was obtained always appears one word before the degree title.

Main Functions

Average Ages

Avages contains a function avg_age which returns the average age of professors in a given year. To determine the average age of professors in 2014, for example, call the avg_age function on the integer 2014.

avg_age(2014)

ages_2 <- function(x) {
prof_info <- system.file("extdata", "2014williamsprofs.txt", package = "avages")
prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2014 prof info into a vector of strings
prof_info_charvec1 <- prof_info_charvec[!grepl("MBA", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA
prof_info_charvec2 <- prof_info_charvec1[!grepl("ABD", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB

pos_of_BA <- grep("BA", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA - 1
pos_of_BS <- grep("BS", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS - 1
pos_of_BM <- grep("BM", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM - 1
pos_of_BE <- grep("BE", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE - 1
pos_of_AB <- grep("AB", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB - 1
pos_of_BFA <- grep("BFA", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA - 1
pos_of_BPhil <- grep("BPhil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil - 1
pos_of_SB <- grep("SB", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
# dates of undergrad degrees always appear one word before degree title in Williams catalogue

years_charvec <- gsub(",", "", prof_info_charvec2[pos_undergrad_dates])
# get rid of commas after years so vector can be converted from strings to integers

years_numvec <- strtoi(years_charvec)
# converts vector of strings into integers so math can be done
ages <- x - years_numvec + 22
}


avg_age <- function(x) {
if (x == 2004 || x == 2005 || x == 2006 || x == 2007 || x == 2008 || x == 2009 ||
x == 2010 || x == 2011 || x == 2012 || x == 2013) {
mean(ages_1(x))
} else if (x == 2014) {
mean(ages_2(x))
} else {
stop("argument not an integer on [2004, 2014]")
}
}

avg_age(2014)

The avg_age function relies on input from the subsidiary ages_1 and ages_2 functions, and simply finds the mean value of the age vectors these subsidiary functions produce for a given year.

If avg_age is called on an argument that is not an integer on [2004, 2014], avg_age will return an error message.

Oldest Professors

The oldst function returns the name(s) and age of the oldest professor/lecturer(s) in a given year. To determine the oldest professor/lecturer employed at Williams in 2014, for example, call the oldst function on the integer 2014.

oldst(2014)

ages_2 <- function(x) {
prof_info <- system.file("extdata", "2014williamsprofs.txt", package = "avages")
prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2014 prof info into a vector of strings
prof_info_charvec1 <- prof_info_charvec[!grepl("MBA", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA
prof_info_charvec2 <- prof_info_charvec1[!grepl("ABD", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB

pos_of_BA <- grep("BA", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA - 1
pos_of_BS <- grep("BS", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS - 1
pos_of_BM <- grep("BM", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM - 1
pos_of_BE <- grep("BE", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE - 1
pos_of_AB <- grep("AB", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB - 1
pos_of_BFA <- grep("BFA", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA - 1
pos_of_BPhil <- grep("BPhil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil - 1
pos_of_SB <- grep("SB", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
# dates of undergrad degrees always appear one word before degree title in Williams catalogue

years_charvec <- gsub(",", "", prof_info_charvec2[pos_undergrad_dates])
# get rid of commas after years so vector can be converted from strings to integers

years_numvec <- strtoi(years_charvec)
# converts vector of strings into integers so math can be done
ages <- x - years_numvec + 22
}


oldst <- function(x) {
if (x == 2013) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2012) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2011) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2010) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2009) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2008) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2007) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2006) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2005) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2004) {
paste("Henry J. Bruton, age", max(ages_1(x)))
} else if (x == 2014) {
paste("Charles B. Dew and Donald deB. Beaver, age", max(ages_2(x)))
} else {
stop("argument not an integer on [2004, 2014]")
}
}

oldst(2014)

The oldst function relies on input from the subsidiary ages_1 and ages_2 functions, and finds the maximum value of the age vectors these subsidiary functions produce for a given year.

If oldst is called on an argument that is not an integer on [2004, 2014], oldst will return an error message.

Youngest Professors

The yngst function returns the name(s) and age of the youngest professor/lecturer(s) in a given year. To determine the youngest professor/lecturer employed at Williams in 2014, for example, call the yngst function on the integer 2014.

yngst(2014)

ages_2 <- function(x) {
prof_info <- system.file("extdata", "2014williamsprofs.txt", package = "avages")
prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2014 prof info into a vector of strings
prof_info_charvec1 <- prof_info_charvec[!grepl("MBA", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA
prof_info_charvec2 <- prof_info_charvec1[!grepl("ABD", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB

pos_of_BA <- grep("BA", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA - 1
pos_of_BS <- grep("BS", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS - 1
pos_of_BM <- grep("BM", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM - 1
pos_of_BE <- grep("BE", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE - 1
pos_of_AB <- grep("AB", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB - 1
pos_of_BFA <- grep("BFA", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA - 1
pos_of_BPhil <- grep("BPhil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil - 1
pos_of_SB <- grep("SB", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
# dates of undergrad degrees always appear one word before degree title in Williams catalogue

years_charvec <- gsub(",", "", prof_info_charvec2[pos_undergrad_dates])
# get rid of commas after years so vector can be converted from strings to integers

years_numvec <- strtoi(years_charvec)
# converts vector of strings into integers so math can be done
ages <- x - years_numvec + 22
}


yngst <- function(x) {
if (x == 2013) {
paste("Daniel Greenberg, age", min(ages_1(x)))
} else if (x == 2012) {
paste("Daniel Greenberg, age", min(ages_1(x)))
} else if (x == 2011) {
paste("Daniel Greenberg age", min(ages_1(x)))
} else if (x == 2010) {
paste("Donald Brooks, Marshall K. Creighton, and Christopher Himes, age", min(ages_1(x)))
} else if (x == 2009) {
paste("Nicholas T. Goodbody and Karen Russell, age", min(ages_1(x)))
} else if (x == 2008) {
paste("Charles N. Howard, age", min(ages_1(x)))
} else if (x == 2007) {
paste("Robert Michelin, age", min(ages_1(x)))
} else if (x == 2006) {
paste("Zafrir Levy, age", min(ages_1(x)))
} else if (x == 2005) {
paste("Zafrir Levy, age", min(ages_1(x)))
} else if (x == 2004) {
paste("Zafrir Levy, age", min(ages_1(x)))
} else if (x == 2014) {
paste("Sarah A. Mirseyedi, age", min(ages_2(x)))
} else {
stop("argument not an integer on [2004, 2014]")
}
}

yngst(2014)

The yngst function relies on input from the subsidiary ages_1 and ages_2 functions, and finds the minimum value of the age vectors these subsidiary functions produce for a given year.

If yngst is called on an argument that is not an integer on [2004, 2014], yngst will return an error message.

Distribution of Ages

Avages' age_hist function produces a histogram displaying the frequency of each age in a given year. To generate such a histogram for the year 2014, for example, call age_hist on the integer 2014.

age_hist(2014)

ages_2 <- function(x) {
prof_info <- system.file("extdata", "2014williamsprofs.txt", package = "avages")
prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2014 prof info into a vector of strings
prof_info_charvec1 <- prof_info_charvec[!grepl("MBA", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA
prof_info_charvec2 <- prof_info_charvec1[!grepl("ABD", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB

pos_of_BA <- grep("BA", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA - 1
pos_of_BS <- grep("BS", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS - 1
pos_of_BM <- grep("BM", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM - 1
pos_of_BE <- grep("BE", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE - 1
pos_of_AB <- grep("AB", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB - 1
pos_of_BFA <- grep("BFA", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA - 1
pos_of_BPhil <- grep("BPhil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil - 1
pos_of_SB <- grep("SB", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
# dates of undergrad degrees always appear one word before degree title in Williams catalogue

years_charvec <- gsub(",", "", prof_info_charvec2[pos_undergrad_dates])
# get rid of commas after years so vector can be converted from strings to integers

years_numvec <- strtoi(years_charvec)
# converts vector of strings into integers so math can be done
ages <- x - years_numvec + 22
}


age_hist <- function(x) {
if (x == 2013) {
hist(ages_1(x), seq(20, 100), col = "red", main = "Prof Ages in 2013",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2012) {
hist(ages_1(x), seq(20, 100), col = "yellow", main = "Prof Ages in 2012",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2011) {
hist(ages_1(x), seq(20, 100), col = "green", main = "Prof Ages in 2011",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2010) {
hist(ages_1(x), seq(20, 100), col = "violet", main = "Prof Ages in 2010",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2009) {
hist(ages_1(x), seq(20, 100), col = "orange", main = "Prof Ages in 2009",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2008) {
hist(ages_1(x), seq(20, 100), col = "blue", main = "Prof Ages in 2008",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2007) {
hist(ages_1(x), seq(20, 100), col = "pink", main = "Prof Ages in 2007",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2006) {
hist(ages_1(x), seq(20, 100), col = "cyan", main = "Prof Ages in 2006",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2005) {
hist(ages_1(x), seq(20, 100), col = "purple", main = "Prof Ages in 2005",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2004) {
hist(ages_1(x), seq(20, 100), col = 128, main = "Prof Ages in 2004",
xlab = "Age", ylim = c(0, 20))
}
else if (x == 2014) {
hist(ages_2(x), seq(20, 100), col = 644, main = "Prof Ages in 2014",
xlab = "Age", ylim = c(0, 20))
}
else {
stop('argument not an integer on [2004, 2014]')
}
}

age_hist(2014)

The age_hist function relies on input from the subsidiary ages_1 and ages_2 functions, and produces histograms from the age vectors these subsidiary functions produce for a given year.

Change in Mean Age Over Time

Avages' age_change function produces a plot, generated by ggplot2, which displays the change in mean age of professors/lecturers at Williams College from 2004 to 2014. To generate this graph, call the age_change function with no argument.

age_change()

ages_1 <- function(x) {
if (x == 2013) {
prof_info <- system.file("extdata", "2013williamsprofs.txt", package = "avages")
}
else if (x == 2012) {
prof_info <- system.file("extdata", "2012williamsprofs.txt", package = "avages")
}
else if (x == 2011) {
prof_info <- system.file("extdata", "2011williamsprofs.txt", package = "avages")
}
else if (x == 2010) {
prof_info <- system.file("extdata", "2010williamsprofs.txt", package = "avages")
}
else if (x == 2009) {
prof_info <- system.file("extdata", "2009williamsprofs.txt", package = "avages")
}
else if (x == 2008) {
prof_info <- system.file("extdata", "2008williamsprofs.txt", package = "avages")
}
else if (x == 2007) {
prof_info <- system.file("extdata", "2007williamsprofs.txt", package = "avages")
}
else if (x == 2006) {
prof_info <- system.file("extdata", "2006williamsprofs.txt", package = "avages")
}
else if (x == 2005) {
prof_info <- system.file("extdata", "2005williamsprofs.txt", package = "avages")
}
else if (x == 2004) {
prof_info <- system.file("extdata", "2004williamsprofs.txt", package = "avages")
}
else {
stop('argument not an integer on [2004, 2014]')
}

prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2013 prof info into a vector of strings

prof_info_charvec1 <- prof_info_charvec[!grepl("M.B.A.", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA

prof_info_charvec2 <- prof_info_charvec1[!grepl("A.B.D.", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB
pos_of_BA <- grep("B.A.", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA + 1
pos_of_BS <- grep("B.S.", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS + 1
pos_of_BM <- grep("B.M.", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM + 1
pos_of_BE <- grep("B.E.", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE + 1
pos_of_AB <- grep("A.B.", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB + 1
pos_of_BFA <- grep("—B.F.A.", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA + 1
pos_of_BPhil <- grep("B.Phil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil + 1
pos_of_SB <- grep("S.B.", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
#dates that undergrad degrees were receieved always appear 1 word after degree titles in Williams catalogue

years_charvec <- gsub("(", "", prof_info_charvec2[pos_undergrad_dates],
fixed = TRUE)
years_charvec1 <- gsub(")", "", years_charvec, fixed = TRUE)
# get rid of parentheses around years so they can be converted from strings to integers

years_charvec2 <- years_charvec1[!grepl("[a-z]", years_charvec1)]
# gets rid of any words that may have slipped through

years_charvec3 <- gsub("203", "2003", years_charvec2, fixed = TRUE)
# because Williams 2012-2013 catalogue accidentally reports that A. Levitt received B.F.A in 202 rather than 2003

years_charvec4 <- gsub("2022", "2002", years_charvec3, fixed = TRUE)
# because Williams 2011-2012 catalogue accidentally reports that J. Joosten received BA in 2022 rather than 2002

years_numvec <- strtoi(years_charvec4)
# converts vector of strings into integers so that math can be done
ages <- x - years_numvec + 22
}

ages_2 <- function(x) {
prof_info <- system.file("extdata", "2014williamsprofs.txt", package = "avages")
prof_info_charvec <- scan(prof_info, what = "character", quiet = TRUE)
#transform plain text document with 2014 prof info into a vector of strings
prof_info_charvec1 <- prof_info_charvec[!grepl("MBA", prof_info_charvec, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have MBA interfering with BA
prof_info_charvec2 <- prof_info_charvec1[!grepl("ABD", prof_info_charvec1, fixed = TRUE)]
#only want to estimate ages with undergrad degrees; can't have ABD interfering with AB

pos_of_BA <- grep("BA", prof_info_charvec2, fixed = TRUE)
pos_of_BA_dates <- pos_of_BA - 1
pos_of_BS <- grep("BS", prof_info_charvec2, fixed = TRUE)
pos_of_BS_dates <- pos_of_BS - 1
pos_of_BM <- grep("BM", prof_info_charvec2, fixed = TRUE)
pos_of_BM_dates <- pos_of_BM - 1
pos_of_BE <- grep("BE", prof_info_charvec2, fixed = TRUE)
pos_of_BE_dates <- pos_of_BE - 1
pos_of_AB <- grep("AB", prof_info_charvec2, fixed = TRUE)
pos_of_AB_dates <- pos_of_AB - 1
pos_of_BFA <- grep("BFA", prof_info_charvec2, fixed = TRUE)
pos_of_BFA_dates <- pos_of_BFA - 1
pos_of_BPhil <- grep("BPhil", prof_info_charvec2, fixed = TRUE)
pos_of_BPhil_dates <- pos_of_BPhil - 1
pos_of_SB <- grep("SB", prof_info_charvec2, fixed = TRUE)
pos_of_SB_dates <- pos_of_SB + 1
pos_undergrad_dates <- c(pos_of_BA_dates, pos_of_BS_dates, pos_of_BM_dates, pos_of_BE_dates, pos_of_AB_dates, pos_of_BFA_dates, pos_of_BPhil_dates, pos_of_SB_dates)
# dates of undergrad degrees always appear one word before degree title in Williams catalogue

years_charvec <- gsub(",", "", prof_info_charvec2[pos_undergrad_dates])
# get rid of commas after years so vector can be converted from strings to integers

years_numvec <- strtoi(years_charvec)
# converts vector of strings into integers so math can be done
ages <- x - years_numvec + 22
}

avg_age <- function(x) {
if (x == 2004 || x == 2005 || x == 2006 || x == 2007 || x == 2008 || x == 2009 || x == 2010 || x == 2011 || x == 2012 || x == 2013) {
mean(ages_1(x))
}
else if (x == 2014) {
mean(ages_2(x))
}
else {
stop('argument not an integer on [2004, 2014]')
}
}

age_change <- function() {
ages1 <- c(avg_age(2004), avg_age(2005), avg_age(2006), avg_age(2007), avg_age(2008),
avg_age(2009), avg_age(2010), avg_age(2011), avg_age(2012), avg_age(2013), avg_age(2014))
# generate mean ages as y values

years1 <- 2004:2014
# generate x values

profdata <- data.frame(years1, ages1)
# create a data frame

library(ggplot2, warn.conflicts = FALSE, quietly = TRUE)
plot <- ggplot(profdata, aes(years1, ages1)) + geom_point(color = "darkviolet")
plot <- plot + ggtitle("Mean Age from 2004 to 2014")
plot <- plot + theme(plot.title = element_text(size = 17.5, face = "bold", vjust = 1,
hjust = 0.5))
# title graph

plot <- plot + labs(x = "Year", y = "Age (yrs)")
# label axes

plot <- plot + theme(axis.text.x = element_text(angle = 50, size = 10, face = "bold",
color = "darkviolet"))
plot <- plot + theme(axis.title.x = element_text(face = "bold", hjust = 0.5, vjust = 0.8))
# format x axis

plot <- plot + theme(axis.text.y = element_text(size = 10, face = "bold", color = "darkviolet"))
plot <- plot + theme(axis.title.y = element_text(face = "bold", hjust = 0.5, vjust = 0.8))
plot <- plot + ylim(c(0, 60))
# format y axis

plot <- plot + theme(plot.background = element_rect(fill = "white"))
plot <- plot + theme(panel.background = element_rect(fill = "gold1"))
# format plot/panel backgrounds

plot
}

age_change()

Avages Results

| Year | Mean Age | Oldest Professor(s) | Youngest Professor(s) | |------:|:---------|---------------------------------------------|:------------------------:| | 2004 | 46.3 | Henry J. Bruton (83) | Zafrir Levy (25) | | 2005 | 46.8 | Henry J. Bruton (84) | Zafrir Levy (26) | | 2006 | 47.1 | Henry J. Bruton (85) | Zafrir Levy (27) | | 2007 | 47.0 | Henry J. Bruton (86) | Robert Michelin (26)| | 2008 | 47.6 | Henry J. Bruton (87) | Charles N. Howard and Karen Russell (23) | | 2009 | 48.0 | Henry J. Bruton (88) | Nicholas T. Goodbody (28)| | 2010 | 49.3 | Henry J. Bruton (89) | Donald Brooks, Marshall K. Creighton, and Christopher Himes (30) | | 2011 | 49.7 | Henry J. Bruton (90) | Daniel Greenberg (25) | | 2012 | 49.9 | Henry J. Bruton (91) | Daniel Greenberg (26)| | 2013 | 49.4 | Henry J. Bruton (92) | Daniel Greenberg (27)| | 2014 | 49.3 | Charles B. Dew and Donald deB. Beaver (78) | Sarah A. Mirseyedi (25) |



tannermlove/avages documentation built on May 31, 2019, 2:58 a.m.