Skip to content

Instantly share code, notes, and snippets.

View pecard's full-sized avatar

Paulo E. Cardoso pecard

  • www.bioinsight.pt
  • Lisbon
View GitHub Profile
@z3tt
z3tt / imp_berlin.R
Last active November 22, 2022 03:53
Imperviousness levels in and around Berlin, Germany
library(tidyverse)
library(sf)
library(terra)
library(stars)
library(ggspatial)
library(systemfonts)
library(patchwork)
register_variant(
name = "Input Mono Light",
@tmasjc
tmasjc / get_rolling_sum.R
Last active February 20, 2019 14:06
Calculate sum for a rolling time window in R #rstats #zoo
# Generate dummy data -----------------------------------------------------
library(dplyr)
library(ggplot2)
library(lubridate)
start_day <- as.Date("2018-01-01")
# 2 Columns - Date & n
dat <- data.frame(date = start_day + days(1:90), n = round(runif(90, 1, 10)))
@mdsumner
mdsumner / efficient-raster-extract.R
Last active August 1, 2017 00:17
Psuedo code summary of realistic NetCDF extraction for polygons
## 80 polygons collectively covering 18k cells in a [681,841] grid
shp_spatial <- as(shp_tab, "Spatial")
## variable has 20k layers (modelled climate metric)
## 681, 841, 20587
filename <- "/path/to/hideous/monstrosity40Gb.nc"
## it's a regular grid, in longlat/WGS84
tbrick <- raster::brick(filename, quick = TRUE, varname = "monster1")
## build cell / polygon mapping
## devtools::install_github("hypertidy/tabularaster")
@ibartomeus
ibartomeus / clean_species
Last active January 23, 2017 08:34
Cleaning species taxonomy using taxize. I want to correct synonyms and typo's and drop incomplete cases.
#I have >1000 bees to check its name, so I want to automatize taxize for
# fixing misspellings when possible
# updating synonims to accepted names
# keeping ONLY accepted species (fully resolved at species level)
# this uses taxize > 0.7.6.9157 If you are using older version (e.g. what its now on CRAN) see the history of this file.
library(taxize)
library(dplyr)
#example: good, synomin, typo, unexisting, genus only.
@lukas-h
lukas-h / license-badges.md
Last active July 11, 2024 07:00
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)

@mick001
mick001 / logistic_regression.R
Last active June 14, 2024 07:59
Logistic regression tutorial code. Full article available at http://datascienceplus.com/perform-logistic-regression-in-r/
# Load the raw training data and replace missing values with NA
training.data.raw <- read.csv('train.csv',header=T,na.strings=c(""))
# Output the number of missing values for each column
sapply(training.data.raw,function(x) sum(is.na(x)))
# Quick check for how many different values for each feature
sapply(training.data.raw, function(x) length(unique(x)))
# A visual way to check for missing data
@mick001
mick001 / poly_reg.R
Last active October 22, 2021 02:20
Polynomial regression in R. Full article available at: http://datascienceplus.com/fitting-polynomial-regression-r/
# Example 1
p <- 0.5
q <- seq(0,100,1)
y <- p*q
plot(q,y,type='l',col='red',main='Linear relationship')
# Example 2
y <- 450 + p*(q-10)^3
plot(q,y,type='l',col='navy',main='Nonlinear relationship',lwd=3)
@gubuntu
gubuntu / SACRS.md
Last active May 12, 2021 15:30
southern African coordinate reference systems (CRS) definitions in proj4 and WKT

Use this file to get the CRS definitions you need in southern Africa, particularly South Africa, Lesotho, eSwatini, Zimbabwe and Namibia.

Most GIS software now implements the South African CRS (SACRS; incorrectly but popularly known as the "LO" system) which is based on south-oriented (or south-facing, 'west-south up') transverse mercator (TMSO). The codes for these are:

  • Hartebeesthoek94 or WGS84 datum (post 1999)
    • EPSG: all numbers from 2046 to 2055
    • ESRI (rather use EPSG): 102480 to 102489
  • Cape datum (for pre-1999 data)
    • EPSG: odd numbers from 22275 to 22293
  • ESRI (rather use EPSG): 102470 to 102479
@benmarwick
benmarwick / citation-analysis-sketch.R
Last active December 14, 2021 15:23
sketch of citation analysis
# sources:
# http://www.jgoodwin.net/?p=1223
# http://orgtheory.wordpress.com/2012/05/16/the-fragile-network-of-econ-soc-readings/
# http://nealcaren.web.unc.edu/a-sociology-citation-network/
# http://kieranhealy.org/blog/archives/2014/11/15/top-ten-by-decade/
# http://www.jgoodwin.net/lit-cites.png
###########################################################################
# This first section scrapes content from the Web of Science webpage. It takes