This file contains 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
rcat <- function(n, labels=c(0, 1), pcts=NULL, seed=12345) { | |
set.seed(seed) | |
catvar <- rep(labels[1], n) | |
if(length(pcts)==0) { | |
interval <- n/length(labels) | |
start <- 1 | |
for(i in 2:length(labels)) { | |
end <- start+interval | |
catvar[start:end] <- labels[i] | |
start <- end+1 |
This file contains 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
# Get ranking graph for multiple choice | |
getmcgraph <- function(t, levels, items, sortby) { | |
t <- lapply(t, function(x) factor(x, levels=levels)) | |
end <- data.frame(matrix(NA, nrow=1, ncol=length(levels))) | |
names(end) <- levels | |
for(i in 1:length(t)) { | |
end <- rbind(end, round(100*prop.table(table(t[i])), digits=2)) | |
} | |
end <- end[-1,] | |
end <- cbind(items, end) |
This file contains 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
## RTutorial.R | |
## Richard Blissett (rsl.bliss@gmail.com) | |
## Code to accompany RTutorial_160930.pdf | |
########################################################### | |
# Set up environment | |
########################################################### | |
# Clear environment | |
rm(list=ls()) |
This file contains 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
# String wrapping for a set of strings | |
wrap_strings <- function(vector_of_strings,width){ | |
sapply(vector_of_strings,FUN=function(x) {paste(wrap_sentence(x,width=width))}) | |
} | |
# Wraps a single sentence | |
wrap_sentence <- function(string, width) { | |
words <- unlist(strsplit(string, " ")) | |
fullsentence <- "" | |
checklen <- "" |
This file contains 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
/* ConvertCCDtoStata_School.do | |
Richard Blissett (rsl.bliss@gmail.com) | |
Finally processes data produced from ConvertCCDtoStata_School.R | |
*/ | |
* Environment settings | |
set more off | |
clear all | |
* Basic information |
This file contains 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
## ConvertCCDtoStata_School.R | |
## Richard Blissett (rsl.bliss@gmail.com) | |
# Environment settings | |
rm(list=ls()) | |
library(haven) | |
# Basic information | |
setwd("~/Documents/CCD Data/School") |