library(tidyverse)
#> Loading tidyverse: ggplot2
#> Loading tidyverse: tibble
#> Loading tidyverse: tidyr
#> Loading tidyverse: readr
#> Loading tidyverse: purrr
#> Loading tidyverse: dplyr
#> Conflicts with tidy packages ----------------------------------------------
#> filter(): dplyr, stats
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
ss <- function(tbl) { | |
fit <- smooth.spline(x = tbl$x, y = tbl$y, cv = TRUE) | |
# first derivative | |
deriv1 <- predict(fit, deriv = 1) | |
slope_max_pos <- which.max(deriv1$y) | |
x_at_slope_max <- tbl$x[slope_max_pos] | |
y_at_slope_max <- tbl$y[slope_max_pos] | |
dy_at_slope_max <- deriv1$y[slope_max_pos] | |
# translate into new vars |
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
# convert cg-12 raw data into generic growth data that can be imported into | |
# precog-lite | |
library(tidyverse) | |
library(lubridate) | |
# devtools::install_github("npjc/cg12r") | |
library(cg12r) | |
# how do you take raw data from the cg-12 and turn it into growth curves |
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
[{"name":"A01","date":"2018-04-19 14:36:36","value":0.078},{"name":"A02","date":"2018-04-19 14:36:36","value":0.077},{"name":"A03","date":"2018-04-19 14:36:36","value":0.082},{"name":"A04","date":"2018-04-19 14:36:36","value":0.285},{"name":"A05","date":"2018-04-19 14:36:36","value":0.081},{"name":"A06","date":"2018-04-19 14:36:36","value":0.08},{"name":"A07","date":"2018-04-19 14:36:36","value":0.142},{"name":"A08","date":"2018-04-19 14:36:36","value":0.083},{"name":"A09","date":"2018-04-19 14:36:36","value":0.077},{"name":"A10","date":"2018-04-19 14:36:36","value":0.101},{"name":"A11","date":"2018-04-19 14:36:36","value":0.078},{"name":"A12","date":"2018-04-19 14:36:36","value":0.077},{"name":"B01","date":"2018-04-19 14:36:36","value":0.076},{"name":"B02","date":"2018-04-19 14:36:36","value":0.079},{"name":"B03","date":"2018-04-19 14:36:36","value":0.08},{"name":"B04","date":"2018-04-19 14:36:36","value":0.08},{"name":"B05","date":"2018-04-19 14:36:36","value":0.102},{"name":"B06","date":"2018-04-19 14:36:3 |
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
year | cw | month | Sun | Mon | Tues | Wed | Thurs | Fri | Sat | |
---|---|---|---|---|---|---|---|---|---|---|
2017 | 2 | Jan | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
2017 | 3 | Jan | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
2017 | 4 | Jan | 15 | 16 | 17 | 18 | 19 | 20 | 21 | |
2017 | 5 | Jan | 22 | 23 | 24 | 25 | 26 | 27 | 28 | |
2017 | 6 | Jan | 29 | 30 | 31 | |||||
2017 | 6 | Feb | 1 | 2 | 3 | 4 | ||||
2017 | 7 | Feb | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
2017 | 8 | Feb | 12 | 13 | 14 | 15 | 16 | 17 | 18 | |
2017 | 9 | Feb | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
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
# install.packages(c("purrr", "tibble")) | |
rtibble <- function(n_obs = 10) { | |
tibble::tibble( | |
lgl = purrr::rbernoulli(n_obs), | |
int = purrr::rdunif(n_obs,sample.int(1e3, 1, replace = T)), | |
dbl = rnorm(n_obs), | |
chr = sample(letters, n_obs, replace = T), | |
fctr = as.factor(sample(letters, n_obs, replace = T)) | |
) |
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
pacman::p_load(readr, dplyr, tidyr, ggplot2) | |
library(partitions) | |
n <- 5 | |
vals <- as.vector(parts(n)) | |
len <- length(vals) / n | |
part <- rep(1:len, each = n) | |
d <- data_frame(vals, part) | |
d <- d %>% | |
group_by(part) %>% |
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
#' the name of the package we want to check | |
pkg <- "tidyr" | |
library(pkg, character.only = TRUE) | |
#' do the work | |
pacman::p_load(readr, dplyr, tidyr, ggplot2) | |
`%||%` <- function(a, b) if (!is.null(a)) a else b | |
ui <- getNamespaceExports(pkg) | |
only_funs <- unlist(lapply(ui, function(x) is.function(get(x)))) | |
ui <- ui[only_funs] | |
l <- lapply(ui, function(f) { |
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
# John Fox's numbers2words found here: | |
# http://tolstoy.newcastle.edu.au/R/help/05/04/2715.html | |
numbers2words <- function(x){ | |
# helper | |
helper <- function(x){ | |
digits <- rev(strsplit(as.character(x), "")[[1]]) | |
nDigits <- length(digits) | |
if (nDigits == 1) as.vector(ones[digits]) | |
else if (nDigits == 2) |
-
use a cache environment in
aaa_cache.R
:bg_ws
for biogrid webservice.- use a function such as
bg_ws_build()
which assigns useful variables- url
- uris (service endpoints)
- access key
- parameters
-
in
zzz.R
:
NewerOlder