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
#' @description Rescale a vector of numbers to an arbitrary range. | |
#' @param minVal The minimum value in the range to rescale your numbers to | |
#' @param maxVal The maximum value on the range to rescale your numbers to | |
#' @param vec The vector you want to rescale | |
#' @example /dontrun{ | |
#' orig <- runif(10,1,30) | |
#' rescaled <- arb_rescale(2,5,orig) | |
#' cbind(orig,rescaled) | |
#' } | |
arb_rescale <- function(minVal,maxVal, vec){ |
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
## Installation | |
install.packages("devtools") | |
library(devtools) | |
devtools::install_github("ropensci/reol") | |
library("Reol") | |
res <- DownloadSearchedTaxa(c("Diceros bicornis","Anolis carolinensis", "Anolis garmani"), to.file=FALSE, exact=TRUE) | |
## Get IUCN status | |
GetIUCNStat(res) | |
### Extract the full page information. |
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(devtools) | |
install_github("ropensci/mdextract",dependencies = TRUE) | |
library(spocc) | |
saltest <- occ("Ambystoma maculatum",from="inat") | |
saltest <- occ2df(saltest) | |
## See a bounding box | |
scov <- coverage_extract(saltest,spatial=list(type="box",lat = "latitude", lon = "longitude",elevation = FALSE)) | |
plot(scov) | |
### Now let's try poly |
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(MASS) | |
library(lars) | |
library(lavaan) | |
####Code to wrap lasso and extra CV... | |
### Taken from: http://www4.stat.ncsu.edu/~boos/var.select/lasso.dr1.txt | |
lasso.dr1<-function(x,y,kfold=5,rep=10,plot=T,grid=seq(from=0,to=1,length=100)){ | |
# wrapper for lasso in lars, with modifications to cv.lars | |
require(lars) |
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
# sapply gone terribly terribly wrong, or used perfectly, I can't tell. | |
# Use: | |
# input: a vector of words, and I want to know are any of the words in input are in the vector out | |
# out: a vector of words that I want to check against, a master list of words | |
# I then want to return an index of TRUE/FALSE to determine if a word is in in the master list | |
input <- c("Lorem","ipsum","testing") | |
out <- c("Loremipsum","qwerty","keyboard","dvorak") | |
dindex <- sapply(input, function(x,y){ind <- grep(x,y);ifelse(length(ind) > 0, for(i in ind){ifelse(x == y[i],return(TRUE),return(FALSE))},return(FALSE))},y=out) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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("sp") | |
library("maptools") | |
options(stringsAsFactors=F) | |
coords <- read.csv("~/Downloads/latlongcoord.csv") | |
biome<-readShapeSpatial("~/Downloads/official/wwf_terr_ecos.shp") | |
### Load subset of data just as a quick test | |
spobj <- SpatialPoints(as.matrix(coords[1:100,c('decimalLongitude','decimalLatitude')])) |
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
knnCont <- function(X, y, k = 4){ | |
y <- y[order(X)] | |
X <- sort(X) | |
x.out <- vector() | |
y.out <- vector() | |
for(x in 1:(length(X)-(k-1))){ | |
x.out <- c(x.out,mean(X[x:(x+(k-1))])) | |
y.out <- c(y.out,mean(y[x:(x+(k-1))])) |
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(sp) | |
library(raster) | |
### Data source: http://nadp.sws.uiuc.edu/ntn/annualmapsByYear.aspx#2012 | |
### Sites provided by sarah | |
# Load up our data | |
depF<-'NO3_dep_2012.tif' | |
concF<-'NO3_conc_2012.tif' | |
sites <- read.csv("neonsites.csv") | |
unprojDep <- raster(depF) |