git branch -m master main
git push -u origin main
git push origin --delete master
But...you can do this as an Rmd with the git commands in a bash chunk
# Problem: | |
# - row 2 of data file has non-data title that repeats every two columns | |
# - column 1 / row 1 header label is fine | |
# - the header in every even-numbered column applies to the next odd-humbered column (eg 2 applies to 3, 4 to 5, etc) | |
# - the header in those odd-numbered columns (3, 5, 7, etc) is read initially as an NA | |
# Solution | |
# - read column names only | |
# - hard code even and odd suffix | |
# - copy header value in those even columns to odd columns |
library(tidyverse) | |
datatab <- as.tibble(c(1:10)) | |
# modulo division | |
datatab$value %% 2 | |
# since we have alternating even and odd value in "value" variable | |
datatab %>% | |
mutate(valueplus = ifelse((value %% 2) == 0, "even", "odd")) |
# quick example of mutate (in the dplyr R package) to create a dummy variable | |
# packages (from the tidyverse) | |
library(tibble) | |
library(dplyr) | |
# a little tibble with an ID number and a gender variable (5 Female, 3 Male, 2 Not Stated) | |
mydata <- tibble(id = 1:10, gender = c("F", "F", "F", "F", "F", | |
"M", "M", "M", | |
"NS", "NS")) |
### --- | |
# | |
# from @expersso | |
set.seed(894) # number of regular season NHL goals Wayne Gretzky scored | |
x <- replicate(10000, sum(sample(0:1, 20, TRUE, c(0.945, 0.055)))) | |
table(ifelse(x == 0, "Team A win", ifelse(x == 1, "Draw", "Team B win"))) / 100 |
--- | |
title: "Transform Data" | |
subtitle: "hands-on examples, with answers" | |
output: html_notebook | |
--- | |
<!-- This file by Charlotte Wickham (with some modifications by Martin Monkman) is licensed under a Creative Commons Attribution 4.0 International License, adapted from the orignal work at https://github.com/rstudio/master-the-tidyverse by RStudio and https://github.com/cwickham/data-science-in-tidyverse-solutions. --> | |
```{r setup} | |
library(tidyverse) |
--- | |
title: "geom_col vs geom_bar" | |
author: "Martin Monkman" | |
date: "2020/04/19" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) |
# 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_ |
# 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") | |