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
#impute NA with group mean | |
df <- df %>% | |
group_by( | |
grouping_column_1, | |
grouping_column_2 | |
) %>% | |
mutate_at( | |
all_of(target_columns), | |
~ ifelse(is.na(.), mean(., na.rm = TRUE), .) | |
) |
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
#!/bin/bash | |
#reprojects in parallel geotif files in MODIS sinusoidal | |
#in the "raw" folder | |
#to geotif files in EPSG 4326 in the current folder | |
#with the suffix "_wgs_84" | |
#listing files in raw | |
for FILEPATH in raw/*; do | |
#generates output file name |
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
#!/bin/bash | |
#reprojects a geotif from MODIS sinusoidal to EPSG 4326 | |
#check https://gdal.org/programs/gdalwarp.html for further details | |
gdalwarp \ | |
-of GTIFF \ | |
-multi \ | |
--config GDAL_CACHEMAX 1024 \ | |
-s_srs '+proj=sinu +R=6371007.181 +nadgrids=@null +wktext' \ | |
-t_srs '+proj=longlat +datum=WGS84 +no_defs' \ | |
-r near \ |
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
# import config. | |
# You can change the default config with `make cnf="config_special.env" build` | |
cnf ?= config.env | |
include $(cnf) | |
export $(shell sed 's/=.*//' $(cnf)) | |
# import deploy config | |
# You can change the default deploy config with `make cnf="deploy_special.env" release` | |
dpl ?= deploy.env | |
include $(dpl) |
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
#R script to plot the CRAN download history of a set of packages | |
library(dlstats) | |
library(ggplot2) | |
target.packages <- c("ranger", "randomForest", "xgboost") | |
x <- dlstats::cran_stats(packages = target.packages) | |
ggplot2::ggplot(data = x) + |
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
#This script downloads soilgrids (https://www.isric.org/explore/soilgrids) data | |
#at a given resolution (variable "res", in degrees) and the depth intervals 0-5 and 5-15 | |
#to compute the mean for the depth interval 0-15. | |
#It also applies the conversion factor shown in the FAQ (https://www.isric.org/explore/soilgrids/faq-soilgrids#How_can_I_access_SoilGrids) | |
#to reconstitute the original data units. | |
library(gdalUtils) | |
library(raster) | |
#variables to download |
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
#installing the development version of the package (v.1.1.1) | |
remotes::install_github( | |
repo = "blasbenito/spatialRF", | |
ref = "development", | |
force = TRUE, | |
quiet = TRUE | |
) | |
library(spatialRF) | |
#loading the example data |
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
#installing and loading package | |
remotes::install_github( | |
repo = "blasbenito/spatialRF", | |
ref = "main", | |
force = TRUE, | |
quiet = TRUE | |
) | |
library(spatialRF) | |
library(magrittr) |
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
#preparing data | |
library(car) | |
data("Prestige") | |
df <- Prestige[, c( | |
"income", | |
"education", | |
"prestige" | |
)] | |
#making a version of education with its range crossing 0 |
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
#returns biodiversity components a, b, and c from two vectors with taxa names. | |
#x: character vector, taxa list of one site | |
#y: character vector, taxa list of another site | |
abc <- function(x, y){ | |
#list to store output | |
out <- list() | |
#filling the list | |
out$a <- length(intersect(x, y)) |
NewerOlder