Code Snippets RMarkdown

Short texts RMarkdown 🧑‍💻 Code snippets RMarkdown ✍️ Reading lists RMarkdown 👀

Week 8 Daily R – Tianhong Yin

“`{r} library(readstata13) library(tidyverse) data % # plot the relationship between GDP and number of years experiencing internal conflicts by population level group_by(firstofname) %>% mutate(pop = as.factor(ifelse(pop >= 16372, “High”, “Low”))) %>% mutate(gdp = mean(gdppc), death = mean(battledeaths), year = length(year)) %>% ggplot(aes(x=year, y=gdppc, color = pop)) + geom_smooth(na.rm = TRUE, se=FALSE) + labs(x=”Number of Years”, […]

Rmarkdown document comparing the performance of Poisson regression vs. casebase for survival analysis in a small dataset (Lung) and a large dataset (ERSPC)

— title: “Poisson vs casebase” author: “Max Turgeon, Jesse Islam and Sahir Bhatnagar” date: “10/1/2021” output: html_document — “`{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) “` # Small dataset: lung “`{r lungSMALLDataset} set.seed(1952) library( mgcv ) library( survival ) library( Epi ) library( popEpi ) library(ggplot2) data( “lung” ) #basic cox model m0.cox

ggplot printing function to make plots the same in interactive RStudio sessions and knitted version

— title: “True Plots” author: “Lisa DeBruine” date: “12/10/2021” output: html_document — “`{r setup, include=FALSE} library(ggplot2) library(dplyr) knitr::opts_chunk$set(echo = TRUE, fig.width = 5, fig.height = 5) “` ## Device size This returns as 10×10 in RStudio when I’m running interactively, and 5×5 when knitting. “`{r} grDevices::dev.size() “` ## Local ggplot print function When running interactively, […]

FisherPermutation.Rmd

— title: “フィッシャーの正確確率検定とパーミュテーションテスト” output: html_document — “`{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) “` ## フィッシャーの正確確率検定 以下のようなテーブルがあるとする。 “`{r} tab

Daily R Week 6 – Tianhong Yin

“`{r} temp = tempfile(fileext = “.xls”) # returns a vector of character strings which can be used as names for temporary files url % mutate(sum_death = sum(DEATH)) %>% ggplot(aes(x=YEAR, y=sum_death)) + geom_smooth() + labs(x=”Year”, y=”Death Count”, title = “Death Count by Year”) + theme_classic() “`