Skip to content

Instantly share code, notes, and snippets.

View grayskripko's full-sized avatar
🏠
Working from home

Gray grayskripko

🏠
Working from home
  • Buenos Aires, Argentina
View GitHub Profile
@grayskripko
grayskripko / rowwise_dplyr.R
Last active July 19, 2019 18:58
Rowwise dplyr
# when you need to use tidyselect in a mutate function
# https://stackoverflow.com/questions/48353331/row-wise-operations-select-helpers-and-the-mutate-function-in-dplyr
tbl %>% mutate(a = select(., contains("abc")))
# based on https://rpubs.com/wch/200398
mtcars %>% purrrlyr::by_row(~any(is.na(.)), .collate = "rows", .to = "has_missing")
tibble(a=c(1, NA, 3), b=c(NA, 2, NA), c=c(NA, 5, 6)) %>%
mutate(pmap_int(., function(...) sum(lift_ld(is.na)(...))))
@sikli
sikli / quantile_speed.R
Last active June 12, 2024 21:02
speeded up R quantile function
#speeded up R quantile function
#code is based on the original quantile function {stats}: https://svn.r-project.org/R/trunk/src/library/stats/R/quantile.R
#This modifed function only supports the 'type 7' quantile algorithm
#The following features were removed (to increase perfomance) :
# - output quantile names
# - error handling such as check if x are factors, or if probs lie outside the [0-1] range
#this makes the speeded up function much more prone to errors, but at the same time faster:
# x <- runif(10000)
@bborgesr
bborgesr / reactives-in-loops.R
Created March 5, 2017 19:20
How to use reactives in loops. What works, what doesn't and why.
# -------------------------------------------------------------------
# ------------------ REACTIVES INSIDE FOR LOOPS ---------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# --- EXAMPLE 1: this works fine, because there are no reactives in -
# --- the for lopp --------------------------------------------------
# -------------------------------------------------------------------
library(shiny)