This file contains hidden or 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(babynames) | |
| library(dplyr) | |
| library(ggplot2) | |
| lifetables %>% | |
| mutate(decade = year)%>% | |
| group_by(decade)%>% | |
| mutate(prob_alive = lx/100000, | |
| study_year = year + x)->prob_people |
This file contains hidden or 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(lme4) | |
| mod <- lmer(F1_n ~ plt_vclass * Decade_c * freq_c + (plt_vclass + freq_c| File) + (Decade_c|word), | |
| data = ays_to_test) | |
| boot_fun <- function(mod){ | |
| # x is a named vector | |
| x <- fixef(mod) | |
| #out is a longer named vector |
This file contains hidden or 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
| libarary(plyr) | |
| library(dplyr) | |
| library(ggplot2) | |
| baseball %>% | |
| group_by(year)%>% | |
| summarise(r=sum(r)) %>% | |
| ggplot(., aes(year, r)) + | |
| geom_point() |
This file contains hidden or 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
| #' SQL Load | |
| #' | |
| #' This is function meant to be used along with ldply to read data in using sqldf. | |
| #' | |
| #' @param x the path to a file to be read | |
| #' @param selection the columns to return. Defaults to \code{"*"} | |
| #' @param condition conditions defining which data rows to load in SQL | |
| #' @param file.format an argument to be passed to \code{sqldf}. | |
| #' Defaults to assume a tab-delimited file with a header row. | |
| #' See \code{?sqldf} for more info |
This file contains hidden or 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
| theKingOfFrance = None | |
| bald = ["JeanLucPicard", "StoneColdSteveAustin"] | |
| print("Jean: The King of France is bald.") | |
| if theKingOfFrance in bald: | |
| print("Jaques: It's true!") | |
| elif theKingOfFrance not in bald: | |
| print("Jaques: It's false!") | |
| print("") |
This file contains hidden or 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
| data.frame(SES = c("High","Middle","Low"), | |
| Applied = c(0.79, 0.59, 0.5), | |
| Admitted = c(0.67, 0.47, 0.42), | |
| Enrolled = c(0.53, 0.28, 0.32)) -> data | |
| ggplot(data, aes(SES)) + | |
| geom_point(aes(y = Applied, color = "Applied"))+ | |
| geom_line(aes(y = Applied, group = 1, color = "Applied"))+ | |
| geom_point(aes(y = Admitted/Applied, color = "Applied and Admitted"))+ | |
| geom_line(aes(group = 1, y = Admitted/Applied, color = "Applied and Admitted"))+ |
This file contains hidden or 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
| multi_match <- function(x, table){ | |
| # returns initial indicies of all substrings in table which match x | |
| if(length(table) < length(x)){ | |
| return(NA) | |
| }else{ | |
| check_mat <- matrix(nrow = length(x), ncol = length(table)) | |
| for(i in 1:length(x)){ | |
| check_mat[i,] <- table %in% x[i] | |
| } | |
| out <- vector(length = length(table)) |
This file contains hidden or 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
| syllabify <- function(trans){ | |
| require(stringr) | |
| segments <- unlist(str_split(trans, " ")) | |
| nuclei_string <- "A|E|I|O|U|@" | |
| nucs <- grep(nuclei_string, segments) | |
| n <- length(nucs) | |
| r_colored <- nucs[grep("R", segments[nucs])] |
This file contains hidden or 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(grid) | |
| bg <- data.frame(xmin = 0, xmax = 180, ymin = 0, ymax = 180) | |
| bg_col <- rgb(0.8,0,0) | |
| bars <- data.frame(xmin = c(35, 35), xmax = c(145, 145), ymin = c(45, 100), ymax = c(80, 135), groups = c("first", "second") ) | |
| bars_col <- rgb(0.9, 0.56, 0.56) | |
This file contains hidden or 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
| # http://www.cdc.gov/nchs/data/nhsr/nhsr010.pdf | |
| n_fem = 604 | |
| h_fem = 162.2 | |
| se_fem = 0.34 | |
| sd_fem = se_fem * sqrt(n_fem) | |
| n_mal = 591 | |
| h_mal = 176.6 | |
| se_mal = 0.38 |