library(tidyx)
library(tidyverse)
#> -- Attaching packages ----------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
#> v ggplot2 3.1.0 v purrr 0.2.5
#> v tibble 1.4.2 v dplyr 0.7.6
#> v tidyr 0.8.1 v stringr 1.3.1
#> v readr 1.1.1 v forcats 0.3.0
#> -- Conflicts -------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
l1 <- list(a = "foo", b = "bar")
l1 %>% mapx(~ paste(., .i, .n))
#> $a
#> [1] "foo 1 a"
#>
#> $b
#> [1] "bar 2 b"
l1 %>% mapx(~ paste(., .i, .n), .t = "chr")
#> a b
#> "foo 1 a" "bar 2 b"
l1 %>% mapx(paste,"X")
#> $a
#> [1] "foo X"
#>
#> $b
#> [1] "bar X"
l1 %>% mapx(function(x,.n) paste(x,.n),"[.n param]")
#> $a
#> [1] "foo [.n param]"
#>
#> $b
#> [1] "bar [.n param]"
l1 %>% mapx(function(x) paste(x, .n))
#> $a
#> [1] "foo a"
#>
#> $b
#> [1] "bar b"
iris[c(1:2,51:52),] %>% mutatex(z = mean(Sepal.Length),.by = vars(Species))
#> # A tibble: 4 x 6
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species z
#> <dbl> <dbl> <dbl> <dbl> <fct> <dbl>
#> 1 5.1 3.5 1.4 0.2 setosa 5
#> 2 4.9 3 1.4 0.2 setosa 5
#> 3 7 3.2 4.7 1.4 versicolor 6.7
#> 4 6.4 3.2 4.5 1.5 versicolor 6.7
iris[c(1:2,51:52),] %>% mutatex(z = mean(Sepal.Length),.by = "Species")
#> # A tibble: 4 x 6
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species z
#> <dbl> <dbl> <dbl> <dbl> <fct> <dbl>
#> 1 5.1 3.5 1.4 0.2 setosa 5
#> 2 4.9 3 1.4 0.2 setosa 5
#> 3 7 3.2 4.7 1.4 versicolor 6.7
#> 4 6.4 3.2 4.5 1.5 versicolor 6.7
iris %>% head %>% mutate_ifx(funs(z = mean),.at = ~startsWith(.,"Pet"))
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Petal.Length_z
#> 1 5.1 3.5 1.4 0.2 setosa 1.45
#> 2 4.9 3.0 1.4 0.2 setosa 1.45
#> 3 4.7 3.2 1.3 0.2 setosa 1.45
#> 4 4.6 3.1 1.5 0.2 setosa 1.45
#> 5 5.0 3.6 1.4 0.2 setosa 1.45
#> 6 5.4 3.9 1.7 0.4 setosa 1.45
#> Petal.Width_z
#> 1 0.2333333
#> 2 0.2333333
#> 3 0.2333333
#> 4 0.2333333
#> 5 0.2333333
#> 6 0.2333333
iris %>% head %>% mutate_ifx(funs(z = mean),.at = vars(Petal.Length))
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species z
#> 1 5.1 3.5 1.4 0.2 setosa 1.45
#> 2 4.9 3.0 1.4 0.2 setosa 1.45
#> 3 4.7 3.2 1.3 0.2 setosa 1.45
#> 4 4.6 3.1 1.5 0.2 setosa 1.45
#> 5 5.0 3.6 1.4 0.2 setosa 1.45
#> 6 5.4 3.9 1.7 0.4 setosa 1.45
iris %>% head %>% mutate_ifx(funs(z = mean),.at = vars(Petal.Length), .keep = "new")
#> z
#> 1 1.45
#> 2 1.45
#> 3 1.45
#> 4 1.45
#> 5 1.45
#> 6 1.45
iris[c(1:2,51:52),] %>% summarizex(z = mean(Sepal.Length),.by = vars(Species))
#> # A tibble: 2 x 2
#> Species z
#> <fct> <dbl>
#> 1 setosa 5
#> 2 versicolor 6.7
iris[c(1:2,51:52),] %>% summarizex(z = mean(Sepal.Length),.by = "Species")
#> # A tibble: 2 x 2
#> Species z
#> <fct> <dbl>
#> 1 setosa 5
#> 2 versicolor 6.7
iris %>% slicex(1:2, .by= vars(Species))
#> # A tibble: 6 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 7 3.2 4.7 1.4 versicolor
#> 4 6.4 3.2 4.5 1.5 versicolor
#> 5 6.3 3.3 6 2.5 virginica
#> 6 5.8 2.7 5.1 1.9 virginica
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.