Skip to content

Instantly share code, notes, and snippets.

@chainsawriot
chainsawriot / gist:8330931
Last active January 2, 2016 16:29
Reading data with multiple comments The comment chars should not be those special regex characters.
### assuming the test.tab have this structure
# hello
# ! This is comment
# # This is also a comment
# 1
# 2
# 3
read.table(text=sub(paste0("[!#]", ".*"), "", readLines("test.tab")), header=TRUE)
@chainsawriot
chainsawriot / arraycolrenames
Created January 2, 2014 17:16
Array rename
testarray <- array(1:6, c(2,3))
dimnames(testarray) <- list(c("a", "b"), c("d", "e","f"))
testarray
dimnames(testarray) <- list(c("H", "K"), c("R", "U","G"))
@chainsawriot
chainsawriot / Example of do.call rbind
Last active January 1, 2016 14:19
Combining list of data.frames into a single data.frame.
# combining list of data frames
irisBroken <- list(iris[1:10,], iris[11:30,])
do.call(rbind, irisBroken)
@chainsawriot
chainsawriot / freqtable
Created February 21, 2013 13:36
Frequency table of Chinese tokens extracted from evchk, zhyue wikipedia and press releases of HKGOV. Released under CC-BY 3.0 unported.
tokens freq
的 366981
一 232555
年 229119
人 190091
有 189779
會 160113
日 144340
月 135667
港 132770