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
agecount <- function(age = NULL) { | |
if (is.null(age)){ | |
stop("age couldn't be NULL") | |
} | |
homicides <- readLines("homicides.txt") | |
r <- regexec("(\\d+) years old", homicides) | |
m <- regmatches(homicides, r) | |
causes <- sapply(m, function(x) as.integer(x[2])) | |
return(length(which(causes==age))) |
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
# Training: Big Data Analyses with R | |
# Exercise 3 | |
Sys.setenv(HADOOP_CMD="/usr/bin/hadoop") | |
Sys.setenv(HADOOP_STREAMING="/usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.2.0.jar") | |
library(rmr2) | |
input <- to.dfs(1:1000) | |
out <- mapreduce( | |
input = input, | |
map = function(k, v) cbind(v, v^2)) |
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
reqURL <- "https://api.twitter.com/oauth/request_token" | |
accessURL <- "http://api.twitter.com/oauth/access_token" | |
authURL <- "http://api.twitter.com/oauth/authorize" | |
consumerKey <- 'consumerKey' | |
consumerSecret <- 'consumerSecret' | |
twitCred <- OAuthFactory$new(consumerKey=consumerKey, | |
consumerSecret=consumerSecret, | |
requestURL=reqURL, | |
accessURL=accessURL, | |
authURL=authURL) |
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
--- from_file | |
+++ untitled 2 | |
@@ -77,16 +77,16 @@ | |
# Get location data | |
cat("Getting data from Twitter, this may take a moment.\n") | |
- tmp = getUser(userName, cainfo="cacert.pem") | |
+ tmp = getUser(userName) | |
if(is.null(userLocation)){ | |
userLocation = location(tmp) |
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
import.packages <- function(pkg) { | |
if (!require(pkg, character.only=TRUE)) { | |
install.packages(pkg, dep=TRUE) | |
require(pkg, character.only=TRUE) | |
} | |
} | |
ip2coordinates <- function(ip, session=getCurlHandle()) { | |
api <- "http://www.datasciencetoolkit.org/ip2coordinates/" | |
get.ips <- getURL(paste(api, URLencode(ip), sep=""), curl=session) |
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
package main | |
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/go-sql-driver/mysql" | |
) | |
func main() { |
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
function search_all(fullst, substr) | |
c = 0 | |
a = search(fullst, substr) | |
while size(a) > (0,) | |
c += 1 | |
a = search(fullst, substr, a[1] + 1) | |
end | |
return c |
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
library(ggplot2) | |
library(grid) | |
line1 <- rnorm(100,mean=15-seq(1,6,by=.05),sd=1) | |
line2 <- rnorm(100,mean=4+seq(1,21,by=.2),sd=.5) | |
time <- seq(1,100,by=1) | |
data <- data.frame(time,line1,line2) | |
ggplot(data,aes(time)) + | |
# The actual lines |
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
library(ggplot2) | |
npoints = 500 | |
npointsb = 1200 | |
opt = theme(legend.position="none", | |
panel.background = element_blank(), | |
panel.grid = element_blank(), | |
axis.ticks = element_blank(), | |
axis.title = element_blank(), | |
axis.text = element_blank()) |
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
library(idbr) # devtools::install_github('walkerke/idbr') | |
library(ggplot2) | |
library(animation) | |
library(dplyr) | |
library(ggthemes) | |
idb_api_key("Your Census API key goes here") | |
male <- idb1('JA', 2010:2050, sex = 'male') %>% | |
mutate(POP = POP * -1, |
OlderNewer