#This is a command that clears everything out of the "environment" giving us a blank slate:

rm(list=ls())

4+3

sqrt(4)

sqrt(4) + 2

#This Line is commented out

#sqrt(4
#)

# 
# sqrt(4)                              +2
# sqrt(4) +2

#Division
5/3
#Multiplication
5*3
#Exponents
5^3
#Using parentheses:
5*(3+3)
#Incorrect (Need the multiplication sign)
#5(3*3)


result <- 5+3

result

result + 2

batman <- 5+3
batman


batman <- "Bruce Wayne"

batman

#Batman

#(Uncomment the below)
#batman/8

Result <- "8"
#Uncomment the below line
#Result/8

8^.5

sqrt(8)

#Yes
sqrt(result)
#No
#sqrt(Result)

nchar(batman)

class(Result)
class(result)
class(sqrt)

#(These are not all the classes)

world.pop <- c(2525,3026,3691,4449,5320,6127,6916)

world.pop

pop1 <- c(2525,3026,3691)
pop2 <- c(4449,5320,6127,6916)

world.pop <- c(pop1, pop2)

#The second item in world.pop
world.pop[2]
#The third entry in world.pop
world.pop[3]

world.pop[c(2,5)]

world.pop[c(2,3,4)]

2:4
1:25

world.pop[2:4]

world.pop
world.pop[-3]

world.pop*1000000

world.pop/world.pop[1]
pop.rate <- world.pop/world.pop[1]
pop.rate

year <- c(1950,1960,1970,1980,1990,2000,2010)

c(year, world.pop, pop.rate)

cbind(year,world.pop,pop.rate)
#We can, of course, save this:
population.table <- cbind(year,world.pop,pop.rate)
population.table

emissions <- c(6,9.33,14.83,19.37,22.7,25.12,33.13)

cbind(year,world.pop,pop.rate, emissions)

population.table <- cbind(population.table, emissions)

population.table[3,1]

population.table[1,3]

population.table[1,1:3]

population.table[1, ]

population.table[ ,2]

mean(population.table[,2])

min(population.table[,2])

max(population.table[,2])

range(population.table[,2])

sum(population.table[,2])

world.pop2 <- c(2525,3026,3691,4449,6127,6916)

world.pop2 <- c(2525,3026,3691,4449,0,6127,6916)

population.table[4,2:3]
population.table[4,2:3] <- NA
population.table

mean(population.table[,2])

mean(population.table[,2],na.rm=TRUE)

#?mean

population.table[4,2:3] <- c(4449,1.76198)
population.table

#install.packages("rio")

#Note that rio is *not* in quotation marks
library(rio)
#If it prompts you to you should also un-comment and run:
#install_formats()

college <- import("https://github.com/marctrussler/IDS-Data/raw/main/college.Rds")

education <- import("https://github.com/marctrussler/IDS-Data/raw/main/education.Rds")
income <- import("https://github.com/marctrussler/IDS-Data/raw/main/income.Rds")
race <- import("https://github.com/marctrussler/IDS-Data/raw/main/race.Rds")

# #You will have to paste your own filepath into the import command
# pa.counties <- import("C:/Users/trussler-adm/PORES Dropbox/PORES/PSCI1800/Data/PACounties.Rds")

getwd()

# setwd("C:/Users/trussler-adm/PORES Dropbox/PORES/PSCI1800/Data")
# pa.counties <- import("PACounties.Rds")
# #Load some other data from this same folder:
# acs <- import("ACSCountyData.csv")

# if(Sys.info()["user"]=="206652XXX"){
#   setwd("C:/Users/206652XXX/PORES Dropbox/Marc Trussler/election-day-turnout/modeling-turnout/GeneralElectionTurnoutModel24")
# } else {
#   setwd("~/PORES Dropbox/Marc Trussler/election-day-turnout/modeling-turnout/GeneralElectionTurnoutModel24")
#   }
# 

# big.data <- rio::import("https://github.com/marctrussler/IIS-Data/raw/refs/heads/main/FullSamples.rds")

# rm(big.data)

mean(population.table[,2])

median(population.table[,2])

sd(population.table[,2])

summary(population.table[,2])

head(college)

mean(college)

median(college)

table(college)

head(table(income))

hist(college)

head(race)

mean(race)

table(race)

barplot(table(race))

table(race)/1000

prop.table(table(race))

head(education)

table(education)

#And use a barplot to visualize the relative frequency
barplot(table(education))




head(income)

mean(income)

median(income)

sd(income)

summary(income)

#table(income)

boxplot(income)

density(income)

plot(density(income))

population.table

boxplot(population.table[,4])
plot(density(population.table[,4]))

#?plot

plot(population.table[,1], population.table[,2])

#plot(population.table[,1], population.table[-1,2])

plot(population.table[,1], population.table[,2],
     main="Global Population Growth",
     xlab="Year",
     ylab="Population (Millions)")

plot(population.table[,1], population.table[,2],
     main="Global Population Growth",
     xlab="Year",
     ylab="Population (Millions)",
     pch=16)

plot(seq(1,25), seq(1,25), pch=seq(1,25))

plot(population.table[,1], population.table[,2],
     main="Global Population Growth",
     xlab="Year",
     ylab="Population (Millions)",
     pch=16,
     col="darkorange")

plot(population.table[,1], population.table[,2],
     main="Global Population Growth",
     xlab="Year",
     ylab="Population (Millions)",
     pch=16,
     col="darkorange",
     type="b")

plot(population.table[,3], population.table[,4],
     xlab="Population Growth vs. 1950",
     ylab="Co2 Emissions (billions of tons)",
     main="Population Growth vs. Co2 Emissions")

plot(population.table[,3], population.table[,4],
     xlab="Population Growth vs. 1950",
     ylab="Co2 Emissions (billions of tons)",
     main="Population Growth vs. Co2 Emissions")
text(population.table[,3], population.table[,4],
     labels=population.table[,1])

plot(population.table[,3], population.table[,4],
     xlab="Population Growth vs. 1950",
     ylab="Co2 Emissions (billions of tons)",
     main="Population Growth vs. Co2 Emissions",
     type="n")
text(population.table[,3], population.table[,4],
     labels=population.table[,1])

pa.counties <- import("https://github.com/marctrussler/IDS-Data/raw/main/PACounties.Rds")
head(pa.counties)

#Basic
plot(pa.counties[,1], pa.counties[,3])
#Full Graph
plot(pa.counties[,1], pa.counties[,3],
     main="Relationship between Population and Median Income in PA",
     xlab="Population", 
     ylab="Median Income",
     pch=16,
     col="Darkblue")

2+2

x <- 2

x+2

plot(c(0,1),c(0,1))
abline(0,1)

plot(c(0,1),c(0,1))

# #None of these variables exist so usually this would error out
# #But eval=F is on so it won't actually be run
# c+2*v^2

# pa.counties <- import("Data/PACounties.Rds"
