###############
# get the data
###############
load("./simulate-data/MICSsimulated.RData") # data in R format
####################
# data wrangling
####################
::look_for(MICSsimulated) # look at data
labelled
<- subset(MICSsimulated,
mynewdata select = c(id, country, aggression)) # subset of data
library(labelled) # variable labels
var_label(MICSsimulated$id) <- "id"
var_label(MICSsimulated$country) <- "country"
var_label(MICSsimulated$cd4) <- "explain"
# make variable into factor
$cd4 <- factor(MICSsimulated$cd4,
MICSsimulatedlevels = c(0, 1),
labels = c("Did not explain",
"Explained"))
# recoding
$aggression[MICSsimulated$aggression > 1] <- NA # recode > 1 to NA
MICSsimulated
$GII[MICSsimulated$GII > 100] <- NA # recode > 100 to NA
MICSsimulated
##############################
# descriptive statistics
##############################
summary(MICSsimulated$GII) # descriptive statistics for GII
table(MICSsimulated$cd4) # frequency table of cd4
Appendix A — A Sample R Script
This is a sample R script for the steps of analysis found in Chapter 6. Usually, an R script is stored in a text file ending in .R
, so this R code could be stored an a text file called myscript.R
.