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
for each item in z List | |
do | |
end for |
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
# Take a random selection of the data | |
set.seed(2014) | |
tdft <- tdft[sample(nrow(tdft), size = 1000), ] | |
# Select only the variables of interest | |
install.packages("dplyr") # library for data manipulation | |
tdft <- select(tdft, lat, lon, created, text, | |
language, n_followers, n_tweets, user_location) |
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
# Remove sensitive text | |
summary(factor(Encoding(tdft$text))) | |
Encoding(tdft$text) <- "UTF-8" | |
tdft$text <- iconv(tdft$text, "UTF-8", "UTF-8",sub='') | |
tdft$text <- gsub('@\\S+', '@', tdft$text) # remove all to '@' texts | |
tdft$text <- gsub('http\\S+', 'http', tdft$text) # remove all to hyperlinks | |
head(tdft$text) |
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 to reduce the max. number of words in a string | |
maxwords <- function(x, max = 10){ | |
lwords <- length(x) | |
if(lwords > max) lwords <- max | |
paste0(x[1:lwords], collapse = " ") | |
} | |
# Apply maxwords to the data | |
tdft$text <- sapply(words, maxwords) |
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
# Download data | |
library(ggmap) # load the ggmap package | |
library(geosphere) | |
download.file("https://dl.dropboxusercontent.com/u/15008199/tmp/origins.csv", "origins.csv", method = "wget") | |
origins <- read.csv("origins.csv") | |
os <- SpatialPoints(coords = origins, | |
proj4string = CRS("+init=epsg:4326")) |
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
# Download data | |
x <- c("ggmap", "geosphere", "sp") | |
lapply(x, library, character.only = TRUE) | |
download.file("https://dl.dropboxusercontent.com/u/15008199/tmp/origins.csv", "origins.csv", method = "wget") | |
origins <- read.csv("origins.csv") | |
os <- SpatialPoints(coords = origins, | |
proj4string = CRS("+init=epsg:4326")) |
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
# Loading MapInfo .mid files | |
library(rgdal) # rgdal library | |
drvs <- ogrDrivers() # ogr capabilities | |
drvs[grep("Inf", drvs$name),] # test MapInfo reading capability of gdal | |
f <- "folder/filename.mid" # filename | |
l <- ogrListLayers(f) # layer name | |
sp_object <- readOGR(f, layer = l[[1]]) # load! |
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
# Install devtools if needed | |
if(!require(devtools)) install.packages("devtools") |
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(plotrix) | |
plot.bike <- function(x, ...){ | |
centre_back <- c(0, x$ws / 2) | |
centre_front <- c(x$ws + x$ttl + 100, x$ws / 2) | |
xlim <- c(-x$ws, centre_front[1] + x$ws / 2) | |
ylim <- c(0, x$ttl + x$ws/2 + 50) | |
plot.new() | |
plot.window(xlim, ylim) | |
draw.circle(x = centre_back[1], y = centre_back[2], radius = x$ws/2) | |
draw.circle(x = centre_front[1], y = centre_back[2], radius = x$ws/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
# Create a class for bicycle data | |
wheelsize <- 559 # 26" wheel size, definited by 'bead seat diameter' (BSD) | |
size <- 21 * 25.4 # top tube length, inches converted to mm | |
top_tube_length <- 530 # top tobe length | |
x <- list(ws = wheelsize, s = size, ttl = top_tube_length) | |
class(x) <- "bike" |
OlderNewer