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
# snippet of code to animate data in order of collection | |
# a little bit of data to show how it works | |
df <- structure(list(sp = structure(c(2L, 2L, 3L, 1L, 1L, 3L, 1L, 3L, | |
2L, 3L, 1L, 3L, 1L, 1L, 3L, 3L, 1L, 2L, 3L, 3L, 1L, 3L, 3L, 1L, | |
3L, 3L, 3L, 3L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 2L, 1L, 1L, 2L, 2L, | |
1L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, | |
3L, 3L, 2L, 2L, 3L, 2L, 1L, 1L, 3L, 2L, 3L), .Label = c("D", | |
"O", "P"), class = "factor"), dbh = c(19.36, 20.74, 10.13, 10.47, | |
10.34, 14.22, 10.17, 22.91, 6.58, 7.93, 14.44, 6.67, 20.93, 7.16, |
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
if(!require(devtools)) install.packages("devtools") | |
devtools::install_github('rstudio/blogdown') | |
library(blogdown) | |
options(servr.daemon = TRUE) | |
install_hugo() # install Hugo | |
new_site() # create folders | |
# install_theme("gcushen/hugo-academic") | |
# install_theme('jbub/ghostwriter') | |
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
library(weatherData) | |
library(plyr) | |
library(dplyr) | |
library(ggplot2) | |
library(tidyr) | |
years = seq(1948, 2015, 1) | |
days = "-03-08" | |
alldays = paste0(years, days) | |
dat_climate = list(length = length(alldays)) |
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
library(stringr) | |
library(RefManageR) | |
## to get citation keys (with forms: author2016title) from tex file | |
get_cite_key = function(tex){ | |
text = readLines(tex) | |
# \cite*{} | |
key_1 = str_replace_all(grep("^.*cite[a-z]{0,7}\\{([A-Za-z0-9,-]*)\\}.*$", | |
x = text, value = T), | |
pattern = "^.*cite[a-z]{0,7}\\{([A-Za-z0-9,-]*)\\}.*$", |
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
# python version | |
known = {0:0, 1:1} | |
def fibonacci(n): | |
if n in known: | |
return known[n] | |
res = fibonacci(n-1) + fibonacci(n-2) | |
known[n] = res | |
return res |
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
# Here are codes to calculate distance of points based on their lat and long coordinations. | |
# The Python version is faster than R version. | |
# Data are presented within R code. For 9 points, in my old laptop, | |
# R took 0.011 seconds while Python used 0.00595 seconds. | |
# For a dataset with 1,000 million points, Python version finished in 20 mins, | |
# but R needs ~62 hours! | |
## R version. ============================================================ | |
library(dplyr) | |
library(sp) |
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
Working with datasets with inconsistent species names is annoying. For example, I am working on resurvey Pine Barrens in central Wisconsin that had been sampled in 1958. However, some species names have been changed overtime. Thus, it is necessary to sync them before data analysis. There is an excellent R package `[taxize](http://ropensci.org/tutorials/taxize_tutorial.html)` for this. However, it is global based thus sometimes can be overwhelming. And I just want to sync my species names with names from the Wisconsin State Herbarium. | |
Until today, I checked species names manually, i.e. search website one by one. This will be fine if I only have one dataset to deal with. Last week, I was trying to build a functional trait dataset from different sources, e.g. carbon and nitrogen before 2013 in one spreadsheet and from this year in another; leaf area and SLA in another; plant height and flower height in another, etc. In addition, it is no clear that whether these spreadsheet have consistent species names! Plus, |