Skip to content

Instantly share code, notes, and snippets.

View padpadpadpad's full-sized avatar
🙃

Daniel Padfield padpadpadpad

🙃
View GitHub Profile
@padpadpadpad
padpadpadpad / mutate_at_base_R_example.R
Last active September 4, 2017 13:29
example using mutate_at() and base R to edit multiple columns indexed from another data frame
# load in packages
library(dplyr)
# create two random dataframes
random <- data.frame(y = rnorm(30, 10), x = rnorm(30, 100), z = rnorm(30, -15))
fixed <- data.frame(y = rnorm(30, 10), x = rnorm(30, 10), z = rnorm(30, 10), a = rnorm(30, 10))
# find columns to change the values of
cols_change <- colnames(fixed)[colnames(fixed) %in% colnames(random)]
# testing non-linear regression methods
# devtools::install_github('padpadpadpad/nlsLoop')
library(nlsLoop)
library(dplyr)
library(tidyr)
library(ggplot2)
library(brms)
library(ggridges)
## ---- setup, echo = FALSE------------------------------------------------
knitr::opts_knit$set(root.dir = normalizePath('../..'))
## ---- load_packages, message = FALSE, warning = FALSE--------------------
# load packages into R
library(rBLAST)
library(taxize)
library(dplyr)
library(tidyr)
library(purrr)
@padpadpadpad
padpadpadpad / get_guardian_crossword.R
Last active November 14, 2017 16:13
code to get Guardian quick crossword
# load packages
library(dplyr)
library(tidyr)
# get today's date and base url in the dataframe
dat <- data.frame(date = as.character(Sys.Date()),
url = 'https://crosswords-static.guim.co.uk/gdn.quick.pdf')
# replace '-' with ''
dat <- mutate(dat, date = gsub('-', '', date))
@padpadpadpad
padpadpadpad / Testing_ips_raxml.R
Last active December 7, 2017 11:13
A rough and ready test of ips::raxml()
# testing ips
library(ips)
library(phyloseq)
# load in example data
data(ips.cox1)
data(ips.16S)
data(ips.28S)
ips <- cbind(ips.cox1, ips.16S, ips.28S,
# phylogenetic tree options
# using fasttree
# load packages
library(phyloseq)
library(tidyr)
library(dplyr)
library(dada2)
# NEED TO INSTALL FASTTREE
# Mothur PCoA Dirk sequencing
library(ggplot2)
library(dplyr)
library(tidyr)
# replace metadata with new metadata
meta_new <- read.csv('~/Desktop/Work/dirk_sequencing/data/metadata.csv', stringsAsFactors = FALSE) %>%
mutate(., time = as.character(time))
@padpadpadpad
padpadpadpad / nls_bootstrap.R
Last active December 19, 2017 23:32
Quick bootstrap of a nls model using dplyr and broom
# quick bootstrap of a TPC model
# load packages
library(ggplot2)
library(dplyr)
library(tidyr)
library(nls.multstart) # devtools::install_github('padpadpadpad/nls.multstart')
library(broom)
library(purrr)
library(patchwork) # devtools::install_github('thomasp85/patchwork')
@padpadpadpad
padpadpadpad / plot_league_tables.R
Last active December 27, 2017 10:36
Use engsoccerdata to plot league tables through time
# Get league tables from engsoccerdata
# Daniel Padfield
# load in packages
library(engsoccerdata)
library(dplyr)
library(tidyr)
library(ggplot2)
# load in data
library(ggplot2)
d <- data.frame(x = rnorm(20), y = rnorm(20))
d$row <- paste('C', row.names(d), sep = '_')
# random plot
ggplot(d, aes(row, y)) +
geom_point()
# order by y, highest first