R language notes | pipes: chaining

df-sum <- df %>%
			mutate(bar = bar(foo)) %>%
			mutate(compare = bar > baz) %>%
			mutate(express = ifelse(compare, "greater than baz",baz )) %>%
			group_by(express) %>%
			summarise(n = n(), mean = mean(bar))

would be equal to

df_sum <- summarise(group_by(mutate(express = ifelse(mutate(compare = mutate(df, bar = bar(foo)) > baz), "greater than baz",baz ))), n = n(), mean = mean(bar))

pipe
%>% takes whatever is on the left of the pipe.
Check if there are the same variables on the left and right. If there are not, uses it as the first argument of the function on the right. Otherwise, rewrites the same variable.

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页