Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher DeSante cdesante

  • Indiana University
View GitHub Profile
@cdesante
cdesante / rPackages
Created Apr 24, 2020
Reinstalling All Packages for R 4.0
View rPackages
#In R 3.6, run:
.libPaths()[1]
#Copy this directory path and paste it on the line below;
#Then run all lines below in R 4.0:
PASTED <- "C:/Users/.../R/win-library/3.6"
currentPackages <- list.dirs(path = PASTED , recursive = FALSE)
currentPackages
trimmed <- stringr::str_replace_all(currentPackages, paste(PASTED , "/", sep = ""), "")
toInstall <- dput(trimmed)
doInstall <- TRUE
View newVersion.R
install.packages("tidyr", dependencies = TRUE)
install.packages("ggplot2", dependencies = TRUE)
install.packages("survey", dependencies = TRUE)
install.packages("gridExtra", dependencies = TRUE)
install.packages("dplyr", dependencies = TRUE)
install.packages("stringr", dependencies = TRUE)
install.packages("tidytext", dependencies = TRUE)
install.packages("mvtnorm", dependencies = TRUE)
install.packages("foreign", dependencies = TRUE)
install.packages("Zelig", dependencies = TRUE)
View turkey2016.r
library(ggplot2)
theme_set(theme_bw())
Turkey <- read.csv("http://pages.iu.edu/~cdesante/turkey.csv")
ggplot(data = Turkey) + geom_tile(aes(x = Happy, y = Thanksgiving, fill=Turkey.Colors
)) + scale_fill_identity() + theme_bw() + labs(title = "Happy Thanksgiving 2016 from is.R()!\n",
x = "", y = "") + scale_x_continuous(breaks = NULL)+ scale_y_continuous(breaks = NULL)
@cdesante
cdesante / Rwords.r
Created Dec 17, 2012
Extracting Numeric Values from Words
View Rwords.r
My.Words <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/Randwords.csv")
My.Words$RANDOM.WORDS <- as.character(My.Words$RANDOM.WORDS)
#Step 1: Split Character Vectors into Sub-strings:
strsplit(My.Words$RANDOM.WORDS, "")
Split.List <- strsplit(My.Words$RANDOM.WORDS, "")
#Step 2: Assign a numeric value to each of the 26 letters:
LETTERS
View basicmap.r
doInstall <- TRUE
toInstall <- c("maps", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
library(maps)
Prison <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/prison.csv")
head(Prison)
View apsrtable.r
doInstall <- TRUE
toInstall <- c("apsrtable")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
#http://cran.r-project.org/web/packages/apsrtable/apsrtable.pdf
library(apsrtable)
View apsrtable.r
doInstall <- TRUE
toInstall <- c("apsrtable")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
#http://cran.r-project.org/web/packages/apsrtable/apsrtable.pdf
library(apsrtable)
View foreign.r
doInstall <- TRUE
toInstall <- c("foreign")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
#http://cran.r-project.org/web/packages/foreign/foreign.pdf
#setwd("your working directory here")
library(foreign)
View happythanksgiving.r
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
Turkey <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/turkey.csv")
ggplot(data = Turkey) + geom_tile(aes(x = Happy, y = Thanksgiving, fill=Turkey.Colors,
width=1))+ scale_fill_identity() + theme_bw()
View hjustvjust.r
hjustvjust <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
text="is-R"
)
hv <- ggplot(hjustvjust, aes(x=hjust, y=vjust)) +
geom_point() +