This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
# start with current year | |
starting_year <- 2024 | |
# assume this many children born during the lifetime of each woman | |
children_per_woman <- 2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# support vector machines # | |
data(quakes) | |
plot( quakes , col = as.factor( round( quakes$mag ) ) ) | |
this_df <- quakes | |
this_df[ , 'mag' ] <- as.factor( round( this_df[ , 'mag' ] ) ) | |
library(e1071) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
baseurl <- "https://washingtondc.craigslist.org/search/doc/jjj" | |
raw_query_list <- | |
lapply( | |
paste0( baseurl , "?s=" , seq( 0 , 1469 , 120 ) ) , | |
xml2::read_html | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tf <- tempfile() | |
download.file( "https://www.ssa.gov/oact/babynames/state/namesbystate.zip" , tf , mode = 'wb' ) | |
z <- unzip( tf , exdir = tempdir() ) | |
state_files <- grep( "\\.TXT$" , z , value = TRUE ) | |
state_list <- lapply( state_files , read.table , header = FALSE , sep = ',' , stringsAsFactors = FALSE ) | |
w <- do.call(rbind,state_list) | |
names( w ) <- c( 'stateab' , 'sex' , 'year' , 'name' , 'count' ) | |
maxes <- with( w , tapply( count , list( year , stateab , sex ) , max ) ) | |
max_df <- reshape2::melt( maxes ) | |
names( max_df ) <- c( 'year' , 'stateab' , 'sex' , 'count' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lubridate) | |
x <- ymd_h( "1999-12-31:23" ) | |
y <- ymd_h( "2000-01-02:01" ) | |
# https://en.wikipedia.org/wiki/UTC%E2%88%9212:00 | |
( x1 <- force_tzs( x , tzone="Etc/GMT+12" , tzone_out="UTC" ) ) | |
# https://en.wikipedia.org/wiki/UTC%2B14:00 | |
( y1 <- force_tzs( y , tzone="Pacific/Kiritimati" , tzone_out="UTC" ) ) | |
difftime( x1 , y1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(survey) | |
data(api) | |
x <- apistrat | |
x <- subset( x , comp.imp == 'Yes' ) | |
dstrat_before<-svydesign(id=~1,strata=~stype, weights=~pw, data=x, fpc=~fpc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
tf <- tempfile() | |
tf2 <- tempfile() | |
# download and unzip | |
download.file( "https://dumps.wikimedia.org/other/pagecounts-ez/merged/2018/2018-05/pagecounts-2018-05-27.bz2" , tf , mode = 'wb' ) | |
R.utils::bunzip2( tf , tf2 , remove = FALSE ) | |
# import and restrict to english |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(survey) | |
library(lodown) | |
cpsasec_cat <- get_catalog( "cpsasec" , output_dir = tempdir() ) | |
lodown( "cpsasec" , subset( cpsasec_cat , year == 2017 ) ) | |
plot( | |
c( 15 , 75 ) , |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- | |
structure(list(name = c("George Washington", "John Adams", "Thomas Jefferson", | |
"James Madison", "James Monroe", "John Quincy Adams", "Andrew Jackson", | |
"Martin Van Buren", "William Henry Harrison", "John Tyler", "James K. Polk", | |
"Zachary Taylor", "Millard Fillmore", "Franklin Pierce", "James Buchanan", | |
"Abraham Lincoln", "Andrew Johnson", "Ulysses S. Grant", "Rutherford B. Hayes", | |
"James A. Garfield", "Chester Arthur", "Grover Cleveland", "Benjamin Harrison", | |
"William McKinley", "Theodore Roosevelt", "William Howard Taft", | |
"Woodrow Wilson", "Warren G. Harding", "Calvin Coolidge", "Herbert Hoover", |
NewerOlder