Fecha de la ultima revisión
## [1] "2021-02-01"
El tema proviene de los siguientes sitios.
English: https://r4ds.had.co.nz/pipes.html
Español: https://es.r4ds.hadley.nz/pipes.html
library(magrittr)
%>%
iris subset(Sepal.Length > mean(Sepal.Length)) %$%
cor(Sepal.Length, Sepal.Width)
## [1] 0.3361992
# Example 1
head(iris)
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | setosa |
4.9 | 3 | 1.4 | 0.2 | setosa |
4.7 | 3.2 | 1.3 | 0.2 | setosa |
4.6 | 3.1 | 1.5 | 0.2 | setosa |
5 | 3.6 | 1.4 | 0.2 | setosa |
5.4 | 3.9 | 1.7 | 0.4 | setosa |
head(iris$Sepal.Length %<>% sqrt)
## [1] 2.258318 2.213594 2.167948 2.144761 2.236068 2.323790
# Example 2
<- rnorm(100)
x head(x, n=10)
## [1] -0.57300818 -2.66290342 0.43319709 0.45699657 1.03790838 0.09755769
## [7] -0.36395359 1.79147565 0.33230936 -0.36733552
%<>%
x %>%
abs
sort
head(x, 20)
## [1] 0.03627992 0.07089837 0.09755769 0.13585312 0.14371857 0.14776025
## [7] 0.16107989 0.16646851 0.17321555 0.18242025 0.18251129 0.19571995
## [13] 0.19948039 0.20325103 0.22255672 0.25648246 0.30316201 0.33041543
## [19] 0.33230936 0.33880104