Skip to content

Instantly share code, notes, and snippets.

View BlasBenito's full-sized avatar

Blas Benito BlasBenito

View GitHub Profile
#impute NA with group mean
df <- df %>%
) %>%
~ ifelse(, mean(., na.rm = TRUE), .)
#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
#reprojects a geotif from MODIS sinusoidal to EPSG 4326
#check 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 \
BlasBenito / Makefile
Created August 10, 2022 16:54 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# 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)
#R script to plot the CRAN download history of a set of packages
target.packages <- c("ranger", "randomForest", "xgboost")
x <- dlstats::cran_stats(packages = target.packages)
ggplot2::ggplot(data = x) +
#This script downloads 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 (
#to reconstitute the original data units.
#variables to download
BlasBenito / engineering_features.R
Last active May 19, 2021 14:01
Shows how spatialRF::rf_interactions() works to find variable combinations (via multiplication and PCA) that improve model transferability.
#installing the development version of the package (v.1.1.1)
repo = "blasbenito/spatialRF",
ref = "development",
force = TRUE,
quiet = TRUE
#loading the example data
BlasBenito / multicollinearity.R
Last active May 19, 2021 08:40
Use of spatialRF::auto_cor() and spatialRF::auto_vif() to reduce multicollinearity in a set of predictors while taking into account a preference order defined by the user..
#installing and loading package
repo = "blasbenito/spatialRF",
ref = "main",
force = TRUE,
quiet = TRUE
BlasBenito / interactions.R
Created March 25, 2021 20:56
Shows how variable interaction shapes change with scaling or a variable having 0 in its range
#preparing data
df <- Prestige[, c(
#making a version of education with its range crossing 0
BlasBenito / functions_betadiversity.R
Last active January 7, 2021 08:30
Functions to compute Simpson's and Sorensen's betas from taxa lists from different sites
#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))