dsparks dsparks

View update R.R
1 2 3 4 5
# installing/loading the latest installr package:
install.packages("installr"); require(installr) #load / install+load installr
updateR()
# Then just follow the prompts...
View Custom font in ggplot2.R
1 2 3 4 5 6 7 8 9 10
require(extrafont)
require(ggplot2)
font_import(pattern = "GIL", prompt = FALSE) # Import Gill family
loadfonts(device="win") # Load them all
fonts() # See what fonts are available
 
zp1 <- ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, label = Species))
zp1 <- zp1 + geom_text(family = "Gill Sans MT")
zp1 <- zp1 + theme(text=element_text(family="Gill Sans Ultra Bold"))
View manipulate example.R
1 2 3 4 5 6 7 8 9 10
aPlotFunction <- function(hh, ss, sz){
zp1 <- qplot(data = cars, x = dist, y = speed,
colour = I(hsv(hh/255, 1, 1)),
shape = I(ss),
size = I(sz))
print(zp1 + theme_bw())
}
 
manipulate(
aPlotFunction(hh, ss, sz),
View Test.md

This is a text. but changed this feel free to delete this.

  • WHy
  • Don't
  • I Try
  • A Bulleted list?

I added this.

View lsos.R
1 2 3 4 5 6 7 8 9 10
# improved list of objects
# From http://stackoverflow.com/a/4827843/479554
 
.ls.objects <- function (pos = 1, pattern, order.by,
decreasing=FALSE, head=FALSE, n=5) {
napply <- function(names, fn) sapply(names, function(x)
fn(get(x, pos = pos)))
names <- ls(pos = pos, pattern = pattern)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.mode <- napply(names, mode)
View drawing_from_hypersphere.R
1 2 3 4 5 6 7 8 9 10
N <- 1000
nDims <- 2
randomNumbers <- rnorm(nDims * N, 0, 1)
randomNumbers <- matrix(randomNumbers, ncol = nDims)
 
plot(randomNumbers)
 
radius = sqrt(rowSums(randomNumbers ^ 2))
randomSphere <- 1/radius * randomNumbers
plot(randomSphere)
View whiteStrokeText.R
1 2 3 4 5 6 7 8 9 10
doInstall <- TRUE
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
 
# Make some random data:
randPoints <- data.frame(x = runif(1000), y = runif(1000))
randPoints$color <- hsv(runif(1000), runif(1000), runif(1000))
 
zp1 <- ggplot(randPoints,
View hashing_function.R
1 2 3 4 5 6 7 8 9
library(digest)
set.seed(1)
 
(x <- sample(1e9, size=6))
# [1] 265508664 372123900 572853364 908207790 201681932 898389685
 
## To hash R's internal representation of these numbers
strtoi(substr(sapply(x, digest), 28, 32), 16L) %% 1e3
# [1] 552 511 233 293 607 819
View find_peaks.r
1 2 3 4 5 6 7 8 9 10
#' Finds the local maxima (peaks) in the given vector after smoothing the data
#' with a kernel density estimator.
#'
#' First, we smooth the data using kernel density estimation (KDE) with the
#' \code{\link{density}} function. Then, we find all the local maxima such that
#' the density is concave (downward).
#'
#' Effectively, we find the local maxima with a discrete analogue to a second
#' derivative applied to the KDE. For details, see this StackOverflow post:
#' \url{http://bit.ly/Zbl7LV}.
View simplest_parallel.R
1 2 3 4 5 6 7 8 9
myFunction <- function(x){prod(1:x)}
myFunction(10)
system.time(lapply(1:10000, myFunction))
library(parallel)
myCluster <- makeCluster(detectCores())
clusterExport(myCluster, ls())
system.time(parSapply(myCluster, 1:10000, myFunction))
stopCluster(myCluster)
Something went wrong with that request. Please try again.