Using the Google Elevation API at the following link https://developers.google.com/maps/documentation/elevation/
This file contains hidden or 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
## Empty list -- just use the empty environment for this. | |
nil <- function() { | |
emptyenv() | |
} | |
## Test if a list is the empty list: | |
is_empty <- function(lis) { | |
identical(lis, nil()) | |
} |
This file contains hidden or 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
# A quick function to save a PBM (http://en.wikipedia.org/wiki/Netpbm_format) | |
# visualize *a lot* of missing data pretty quickly (outside of R). | |
writeMissingPBM <- function(x, file) { | |
dims <- dim(x) | |
x[] <- as.integer(is.na(x)) | |
con <- file(file, open="wt") | |
writeLines(sprintf("P1\n%d %d", ncol(x), nrow(x)), con) | |
write.table(x, file=con, sep=" ", col.names=FALSE, row.names=FALSE, quote=FALSE) | |
close(con) |
This file contains hidden or 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
--- | |
title: "Row bind a list of data.frames with a key" | |
author: "Jenny Bryan" | |
date: "22 August, 2014" | |
output: | |
html_document: | |
keep_md: TRUE | |
--- | |
I posed a question on Twitter (click to see the figure!): |
This file contains hidden or 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
# You should totally ignore this because it's the first piece of Julia I've ever written. | |
# 2-clause BSD, blah. | |
function make_cycle(n) | |
result = Dict{Int32, Array{Int32}}() | |
for i = 1:n | |
ii = i - 1 | |
push!(result, i, [1 + ((i+n-2) % n), 1 + i % n]) | |
end | |
result |
This file contains hidden or 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
# convert c("female", "Male") to c(0,1) | |
# magrittr is way nicer than nested function calls | |
convert_sexcodes <- | |
function(codes) | |
{ | |
require(magrittr) | |
tolower(codes) %>% |
What if a function in a package has no examples? Or is poorly exampled? Wouldn't it be nice to find functioning instances of it "in the wild"?
Via Twitter, Noam Ross taught me a clever way to do such searches on GitHub. Put this into the GitHub search box to see people using the llply()
function from plyr
:
"llply" user:cran language:R
Or just click here.
This file contains hidden or 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
### Colours of old Smarties with lovely artificial colouring, derived from: | |
### | |
### | |
### "Smarties old new" by John Penton and Paul Hughes - Own work. Licensed under CC BY-SA 2.5 via Wikimedia Commons - https://commons.wikimedia.org/wiki/File:Smarties_old_new.jpg#mediaviewer/File:Smarties_old_new.jpg | |
### | |
### image was loaded into gimp, representative parts of each Smartie were isolated, the image converted to indexed palette | |
### with 9 colours, the palette then saved. | |
## | |
### "Smarties" is a trademark of Nestle | |
## |
Playing with adding +
operator for easily joining geojson objects together into a single
valid geojson object. This is relatively easy with lists, but not so easy with json unless you speak json.
Get lawn
package too for viewing data
devtools::install_github("ropensci/geojsonio")