FIND DATA: By Author | Journal | Sites   ANALYZE DATA: Help with R | SPSS | Stata | Excel   WHAT'S NEW? US Politics | Int'l Relations | Law & Courts
   FIND DATA: By Author | Journal | Sites   WHAT'S NEW? US Politics | IR | Law & Courts
Run R Code
About This Page
This page features live demonstrations of the R Statistics Program used for political science research.
  • To run example, click the Run button.
  • To copy example code, click the Copy button.


See More R Demos
Run R Code in Your Web Browser
# Explore contents of variable in dataset
#############################################################
library("poliscidata")
# You need to load the poliscidata package each time at the start of each session/script.
# You should also always set a working directory, but this demo script is running on a remote server.
#############################################################

# Explore specific variable in the NES dataset: opinions about death penalty.
# The deathpen variable is the 370th variable/column in our NES dataset, so it is nes[,370]
# Rather than reference by column number, it is much easier to reference it by name.
# To keep the output simple, we are only viewing first 20 observations.
# The levels() command shows you all the unique values of a variable.
cat("First 20 responses to death penalty question in the dataset:\n")
nes$deathpen[1:20]

cat("\n\nLevels of the variable values:\n")
levels(nes$deathpen)

# Describe national opinions about the death penalty using table and figure.
# Use sample weights so the statistics are nationally representative.
cat("\n\nFrequency Distribution Table:\n")
freqC(nes$pid_x, nes$wt)
Watch & Learn
Run R Demo
i
Demonstrates a powerful visual application of correlation analysis..
 Creating Map from Correlation Matrix Demo.
thumbnail preview
â–º
i
Video tutorial & demo by Barry Edwards for R Companion to Political Analysis, 3rd Ed. (19:34).
 Plotting Means With RCPA3's CompmeansC Function
MORE VIDEOS: See Video Channels for more political science videos!
LEARN HOW: Watch Lecture Videos for Essentials of Political Analysis, Video Tutorials for R, Stata, SPSS, and Excel