USsenateClass {Ecdat} | R Documentation |
For all indiviuals in x
with houseSenate
== "Senate", look
up their state
and surname
in the reference table
senate
and return their Class
. For indivuals not found
in senate
, return x[[district]]
.
Senate classes 1, 2 and 3 have their normal elections in 6-year cycles including 2000, 2002, and 2004 (or 2012, 2008, and 2010), respectively. When vacancies occur out of cycle, the vacancy is first filled with appointment by the governor of the state, and an election to fill that seat occurs in the next even-numbered year; the class of that seat does not change.
For example, South Carolina Senator Jim DeMint resigned effective January 1, 2013. South Carolina Governor Nikki Haley appointed Tim Scott to serve until a special election in 2014. This is a Class 3 seat, which means that another election for that seat will occur in 2016.
USsenateClass(x, senate=readUSsenate(), Office='Office', state='state', surname='surname', district='district', senatePattern='^Senate')
x |
|
senate |
|
Office |
name of a character or factor variable |
state |
Standard 2-letter abbreviation for the state of the US |
surname |
the name of a column of |
district |
name of a column of |
senatePattern |
a regular expression for identifying the senators from |
The current algorithm may fail if both senators in a state
have
the same surname
.
a data.frame
with one row for each row of x
and
the following columns:
incumbent |
logical vector: |
District |
a character vector containing the desired NOTES: 1. Incumbents can be missed if the spelling of the surname is
different between 2. If one but not two incumbents is found, others are currently assigned to the class of an incumbent not found. This could be a mistake, because the person could be a previous incumbent or could have lost to the incumbent in the last election. |
Spencer Graves
tst <- data.frame(Office=factor(c("House", "Senate", "Senate", 'Senate')), state=factor(c('SC', 'SC', 'SC', 'NY')), surname=c("Jones", "DeMint", "Graham", 'Smith'), district=c("9", NA, NA, NA), stringsAsFactors=FALSE) tst. <- USsenateClass(tst) chk <- data.frame(incumbent=c(NA, FALSE, TRUE, FALSE), district=c("9", "3", "2", "1 or 3"), stringsAsFactors=FALSE) all.equal(tst., chk) ## ## test with names different from the default ## tst2 <- tst names(tst2) <- letters[1:4] tst2. <- USsenateClass(tst2, Office='a', state='b', surname='c', district='d') all.equal(tst., tst2.)