Skip to content

Instantly share code, notes, and snippets.

View Andrei-WongE's full-sized avatar
💭
I may be slow to respond.

Andrei-WongE Andrei-WongE

💭
I may be slow to respond.
View GitHub Profile
@hadley
hadley / .gitignore
Last active February 25, 2024 02:10
Benchmark different ways of reading a file
.Rproj.user
.Rhistory
.RData
*.Rproj
*.html
@CarlRevell
CarlRevell / Microsoft-Word-reverse-page-numbering
Created December 30, 2013 15:49
Using a combination of Ctrl-F9 (to insert field codes), F9 (to show field codes) and Alt-F9 (not sure) I inserted the following formula into the document footer to display reverse page numbers.
{= {NUMPAGES} - {PAGE} + 1}
Automate Chunks of Analysis in R Markdown
========================================================
```{r setup, echo=FALSE}
library(knitr)
library(DT)
```
```{r create-datasets, echo=FALSE}
@rafapereirabr
rafapereirabr / stacked_map_R_ggplot2.md
Last active March 29, 2023 18:41
Creating a stacked map in R using ggplot2

This gist shows in two steps how to tilt and stack maps using ggplot2 in order to create an image like this one: [![enter image description here][1]][1]

Let's load the necessary libraries and data to use a reproducible example:

# load libraries
  library(rgeos)
  library(UScensus2000tract)
  library(ggplot2)
---
title: "Outliers are a matter of opinion?"
author: "Antony Unwin"
date: ' '
output: html_document
---
```{r include=FALSE}
library(ggplot2)
library(ggthemes)
library(OutliersO3)
@thomasp85
thomasp85 / pdf_animation.rmd
Created October 11, 2018 19:40
An example of embedding a gganimate animation in a pdf
---
title: "PDF Animation Test"
output: pdf_document
header-includes:
- \usepackage{animate}
---
`gganimate` now supports animations inside PDF documents. This feature is only
viewable with Acrobat Reader, however. Remember to include
`\usepackage{animate}` in the preamble and set `fig.show='animate'` in the chunk
library(tidyverse, warn.conflicts = FALSE)
# data frame
mtcars
# as tibble
as.tibble(mtcars)
# rownames_to_column()
rownames_to_column(mtcars)
library(tidyverse)
library(Deriv)
library(scales)

# Formula for polynomial curve: 60x^4 + 5x + 6
#
# I invented this by using WolframAlpha to fit a polynomial linear model that
# when through a set of specific points using this command (with a maximum
# exponent of 4):
library(tidyverse)
df <- mtcars %>%
mutate(
# here 20, 25 are the cut points
region = cut(mpg, c(min(mpg), 20, 25, max(mpg)))
)
ols <- lm(hp ~ region * mpg, df)
summary(ols)
#!/usr/bin/env bash
cat << EOF > ./$1.Rproj
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes