vcd & vcdExtra http://cran.r-project.org/web/packages/vcd/ http://cran.r-project.org/web/packages/vcdExtra/
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
# modified from / inspired by @GShotwell | |
# gist: https://gist.github.com/GShotwell/b19ef520b6d56f61a830fabb3454965b | |
df <- tibble( | |
value = rnorm(100, 50, 10), | |
date = seq.Date(from = ymd("2022-01-01"), | |
ymd("2022-04-10"), | |
by = "day")) | |
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
# OBJECTIVE: | |
# * latitude and longitude stored with degrees with degree symbol and minutes with decimal | |
# * separate into two columns for each, with degrees and minutes separated | |
# step 1 - create a test tibble called "geo_loc" | |
geo_loc <- tribble( ~ latitude, ~ longitude, | |
"48º 4.206", "124º 45.553", | |
"46º 59.4942", "124º 12.6362") | |
# --- | |
# step 2 - split into degrees and minutes columns |
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
# {dplyr}'s `ungroup()` function | |
```{r} | |
# packages | |
library(gapminder) | |
library(dplyr) | |
``` | |
In this example, we calculate the difference in a country's life expectancy from the continent's mean life expectancy | |
- for example, the difference between life expectancy in Canada and the mean life expectancy of countries in the Americas |
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
penguins <- palmerpenguins::penguins | |
penguins %>% | |
filter(!is.na(sex)) %>% | |
mutate(bm_quart = gtools::quantcut(body_mass_g, q=4)) | |
penguins_2 <- penguins %>% | |
filter(!is.na(sex)) %>% | |
select(species, sex, body_mass_g) %>% | |
# mutate(bm_quart = gtools::quantcut(body_mass_g, q=4)) |
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: "rename github repo" | |
author: "Martin Monkman" | |
date: "2020/10/05" | |
output: html_document | |
--- | |
From | |
https://www.r-bloggers.com/2020/07/5-steps-to-change-github-default-branch-from-master-to-main/ |
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
# short script to install the {annotater} package | |
# reference: https://github.com/luisDVA/annotater | |
# Step 1: install the {remotes} package | |
install.packages("remotes") | |
# Step 2: install {annotater} from the GitHub source | |
remotes::install_github("luisDVA/annotater") | |
The creation of random numbers, or the random selection of elements in a set (or population), is an important part of statistics and data science. From simulating coin tosses to selecting potential respondents for a survey, we have a heavy reliance on random number generation.
R offers us a variety of solutions for random number generation; here's a quick overview of some of the options.
One simple solution is to use the runif
function, which generates a stated number of values between two end points (but not the end points themselves!) The function uses the continuous uniform distribution, meaning that every value between the two end points has an equal probability of being sampled.
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
# dplyr::case_when to find and clean FSA | |
# | |
# Notes: | |
# * FSA = "Forward Sortation Area" in Canadian postal parlance | |
# * the regex finds British Columbia FSAs (starting with "V") | |
FSA_list <- df %>% | |
mutate(FSA_clean = case_when( | |
str_detect(FSA, "V\\d.$") == TRUE ~ FSA, | |
TRUE ~ NA_character_ |
NewerOlder