This file contains hidden or 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
# A function to back fill NAs in a vector with the last non-NA value | |
# https://gist.github.com/garyfeng/27e7f8e406192a8cb33a | |
backFillNA<- function (x) { | |
nas<- which(is.na(x)) | |
# trick from http://stackoverflow.com/questions/24837401/find-consecutive-values-in-vector-in-r | |
naList<-split(nas, cumsum(c(1, diff(nas) != 1))) | |
# get the backfill values | |
valueList<-lapply(naList, function(nalist) { | |
prev<- nalist[1]-1 |
This file contains hidden or 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
# I am mystified by how Traminer handles the data format. | |
# Here's the data from the 2015 NAEP Reading tryout study, SC block | |
# where I transformed the data to simplify the structure. | |
# Then I try to use seqformat() or seqdef() to turn the existing data frame | |
# in to a TraMineR object. | |
sc %>% filter(readingTime>0) %>% group_by(student) %>% arrange(readingTime) %>% | |
mutate(c1=1:n(), c2=2:(n()+1), t0=c(1, readingTime[1:n()-1])) %>% | |
select(student, c1, c2, state2, t0, readingTime, event2) %>% na.omit() ->scSPELL |
This file contains hidden or 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
# A function that takes a vector or a list of strings and a regex pattern, | |
# and returns a vector of strings that matches the regex patterns. Don't | |
# have parameter checking, error handling, etc. | |
# The key lesson learned is that regmatches() is badly designed | |
# as it silently drops any non-matched elements. As a result, the length | |
# of the returned vector may nor may not be the same as the input. | |
# had to use the good-o substring() trick. | |
# The second lesson is that when the regex pattern contains several (), such |
This file contains hidden or 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
// see range.js and selection.js for the source | |
// so we have 3 things to work with: | |
// CKEditor.dom selections, ranges, and bookmarks | |
// first, to get the CKeditor instance, use | |
var editor = CKEDITOR.instances.editor1; | |
// selection something in the editor, and get the selection: | |
var sel = editor.getSelection(); |
This file contains hidden or 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
# r code to test and install libraries if not already installed. | |
# code taking from stackoverflow | |
pkgInstall <- function(x) | |
{ | |
if (!require(x,character.only = TRUE)) | |
{ | |
install.packages(x,dep=TRUE) | |
if(!require(x,character.only = TRUE)) stop("Package not found") | |
} |
NewerOlder