🚴♂️
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(dplyr) | |
library(stringr) | |
df <- data.frame(a = c(" aZe aze s", "wxc s aze "), | |
b = c(" 12 12 ", "34e e4 "), | |
stringsAsFactors = FALSE) | |
df <- df %>% | |
rowwise() %>% | |
mutate_all(funs(str_squish(.))) %>% | |
ungroup() |
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
# integers, tuples: "=" makes a copy of the object. Changes of the original object after "=" instruction doesn't affect the copy. | |
a = 2 | |
b = a | |
a = 3 | |
print(a) # 3 | |
print(b) # 2 | |
# tuples | |
a = (2, 3) | |
b = a |
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
#' Function to caclulate the theoretical maximum Heart Rate (HRmax) | |
#' | |
#' @param sex (character) "M" or "F" | |
#' @param age (numeric) Age in years | |
#' @param weight (numeric) Weight in kilograms | |
#' | |
#' @return theoretical maximum Heart Rate | |
#' @examples | |
#' get_HRmax(sex = "M", age = 35, weight = 61) | |
#' |
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
devtools::install_github("ropensci/rgbif") | |
library(rgbif) | |
library(tidyverse) | |
library(rgbif) | |
# GBIF taxon keys (from Manual of Alien Plants of Belgium) | |
keys <- c(141264614, 8421432) | |
# The issues are returned as codes | |
example_duplicates <- map_df(keys, |
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
--- | |
title: "Compare CSV and DwC files from GBIF internetsite, GBIF manual downloads and `rgbif` authomatic downloads" | |
author: | |
- Damiano Oldoni | |
date: "October 16, 2018" | |
output: | |
html_document: | |
toc: true | |
toc_depth: 3 | |
toc_float: 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
--- | |
title: "Check correctness downloads with query parameter `hasCoordinate`" | |
author: | |
- Damiano Oldoni | |
date: "October 18, 2018" | |
output: | |
html_document: | |
toc: true | |
toc_depth: 3 | |
toc_float: 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
#' Change value of a column (\code{remarks}) for rows with some fields equal to some rows in a second df (called here \code{df_ref}). | |
#' Notice that all \code{pmap()} family of functions demands same number of columns as the input df. | |
#' It is strongly recommended to use the column names as inputs of the function of \code{pmap()}. | |
#' In this specific example we require that \code{col3} is of type \code{character} and we use \code{pmap_chr()} to return a character. | |
library(purrr) | |
library(dplyr) | |
df <- | |
df %>% |
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(readr) | |
col_types <- cols( | |
acceptedNameUsage = col_character(), | |
acceptedNameUsageID = col_character(), | |
accessRights = col_character(), | |
associatedReferences = col_character(), | |
associatedSequences = col_character(), | |
associatedTaxa = col_character(), | |
bed = col_character(), | |
behavior = col_character(), |
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
# Example 1: select rows of data with NA in all columns starting with substring bb_: | |
filtered_data <- | |
data %>% | |
filter_at(vars(starts_with("bb_")), all_vars(is.na(.))) | |
# Example 2: filter rows of data with NA in one of the columns starting with substring bb_: | |
filtered_data <- | |
data %>% | |
filter_at(vars(starts_with("bb_")), any_vars(is.na(.))) |
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
# Dummy df | |
df_1 <- tibble::tibble(col1 = c("a","b"), | |
col2 = c(1,2)) | |
# Name new column | |
new_col <- "col3" | |
# Add new column | |
dplyr::mutate(df_1, !!new_col := paste0(col1, ":", col2, ".")) |
OlderNewer