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
def inve(x): | |
print(type(x), x) | |
s = pd.Series([1,2,3]) | |
s.pipe(inve) # series | |
s.apply(inve) # int 1 | |
s.transform(inve) # int 1 | |
s.map(inve) # int 1 |
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
tibble(a=1:3, b=2:4) %>% mutate(c = pmap_dbl(., ~.x + .y)) | |
suppressPackageStartupMessages(library(tidyverse)) | |
tibble(a=1:3, b=2:4, c=3:5) %>% mutate(c = pmap_dbl(list(a, b, c), ~.x + .y + ..3)) | |
#> # A tibble: 3 x 3 | |
#> a b c | |
#> <int> <int> <dbl> | |
#> 1 1 2 6 | |
#> 2 2 3 9 | |
#> 3 3 4 12 |
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
foo <- function() { | |
a <- 1 | |
b <- 2 | |
quos(a, b) %>% map(as_label) %>% set_names() %>% map(get) | |
} |
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
debug(remotes:::github_DESCRIPTION) | |
# do you really need install_github? Create a new project? |
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
$dir = "C:\" | |
Set-Location $dir | |
$urlR = "https://cran.r-project.org/bin/windows/base/old/3.5.1/R-3.5.1-win.exe" | |
$outputR = "$dir\R-win.exe" | |
$wcR = New-Object System.Net.WebClient | |
$wcR.DownloadFile($urlR, $outputR) | |
Write-Output "Download completed" | |
Start-Process -FilePath $outputR -ArgumentList "/S /v/qn /VERYSILENT" -Wait |
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
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"numberOfInstances": { | |
"type": "string", | |
"metadata": { | |
"description": "Number of VMs to deploy." | |
} | |
}, |
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
# we have 2 positive normal distributed features | |
rnorm20 <- purrr::partial(rnorm, mean = 20) | |
a <- rnorm20(1e5) %>% pmax(0.01) # they are positive | |
b <- rnorm20(1e5) %>% pmax(0.01) | |
# we produce 4 interactions with "opers" | |
opers <- c("+", "-", "/", "*") | |
# What are the correlations between them? |
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
# now it works! | |
mean_cust <- function(...) partial(mean, !!!list(...)) | |
mean_cust(na.rm = T)(c(1:3, NA)) | |
# >[1] 2 |
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
# see also https://community.rstudio.com/t/mutate-for-rows/23111 | |
df_with_one_dtype %>% | |
rownames_to_column() %>% | |
gather(var, value, -rowname) %>% | |
spread(rowname, value) | |
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
tibble(a = 1, b = 2) %>% | |
mutate(c = 3) %>% | |
select(1:(one_of("b") - 1), last_col(), everything()) # a c b |