⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
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
#_______________________________________________________________________________# | |
#| |# | |
#| !! keep in mind that each data frame must have only one common field name!! |# | |
#|_____________________________________________________________________________|# | |
#create the function for csvs | |
merge.csv = function(mypath){ | |
filenames=list.files(path=mypath, full.names=TRUE) | |
datalist = lapply(filenames, function(x){read.csv(file=x,header=T, stringsAsFactors=F)}) |
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
#// Say you were building a dataset and wanted to automatically | |
#// generate variable names by some pattern. | |
#// For instance, you might want to do this with population counts | |
#// within 100 census tracts by race | |
#// IE: | |
# | |
# tracts <- paste("c", rep(1:100), sep="") | |
# race - c("black", "white", "hispanic") | |
# | |
#// In this case you would want to generate 300 unique variable names |
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
path_to_file = "~/Desktop/Vizzuality-cartodb-r-05eb537/CartoDB_1.4.tar.gz" | |
install.packages(path_to_file, repos=NULL, type="source") | |
require("CartoDB") | |
account_name = "parks-datadive" | |
api_key = "[ON THE BOARD IN 517-F]" | |
cartodb(account_name, api_key) | |
cartodb.test() |
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
# Get a lat/lon value for each address | |
geocode.addr <- function(city, country) { | |
geo.url <- "http://maps.googleapis.com/maps/api/geocode/json?address=" | |
geo.text <- getURL(paste(geo.url, URLencode(paste(city, country, collapse="+")), "&sensor=false", sep="")) | |
geo.json <- fromJSON(geo.text) | |
if(geo.json$status == "OK"){ | |
return(geo.json$results[[1]]$geometry$location) | |
} | |
else{ |
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
print(paste("step", i)) | |
print(paste(i/n*100, "%")) |
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
find: ([a-z]) (["])([a-z]) | |
replace: $1 \\$2$3 | |
find: ."" | |
replace: ./"" | |
find: ([a-z])(["]) ([a-z]) | |
replace: $1\\$2 $3 |
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
# fill area under a line: | |
plot(x,y, type="n) | |
lines(x,y) | |
polygon( c(min(x), x, max(x)), c( min(y), y, min(y)), density=100 ) |
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
geocode.addr <- function(uid_query) { | |
require("rjson") | |
require("RCurl") | |
require("plyr") | |
uid <- uid_query$uid | |
query <- uid_query$query | |
geo.url <- "http://maps.googleapis.com/maps/api/geocode/json?address=" | |
geo.text <- try(getURL(paste(geo.url, URLencode(query), "&sensor=false", sep=""))) |
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
# helper function: get number of words in a string, separated by tab, space, return, or point. | |
nwords <- function(x){ | |
res <- strsplit(as.character(x), "[ \t\n,\\.]+") | |
res <- lapply(res, length) | |
unlist(res) | |
} | |
# sanitize file name for terminal usage (i.e., escape spaces) | |
sanitize <- function(str) { | |
gsub('([#$%&~_\\^\\\\{}\\s\\(\\)])', '\\\\\\1', str, perl = TRUE) |