%>%
此管道函数介绍请看上一篇文章详解
%<>%
iris$Sepal.Length %<>% sqrt
x <- rnorm(100)
x %<>% abs %>% sort
is_weekend <- function(day)
{
# day could be e.g. character a valid representation
day %<>% as.Date
result <- day %>% format("%u") %>% as.numeric %>% is_greater_than(5)
if (result)
message(day %>% paste("is a weekend!"))
else
message(day %>% paste("is not a weekend!"))
invisible(result)
}
%$%
从前一个dataframe 或者 list 中直接索引对象,和 ”$“ 方法等价。
iris %>%
subset(Sepal.Length > mean(Sepal.Length)) %$%
cor(Sepal.Length, Sepal.Width)
data.frame(z = rnorm(100)) %$%
ts.plot(z)
%T>%
这个就是 %>% 的 double 版,可以将参数同时传递给后面两个函数。
rnorm(200) %>%
matrix(ncol = 2) %T>%
plot %>% # plot usually does not return anything.
colSums
网友评论