本文介绍了了解%>%运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 对于一个noob问题,我很新,但我需要帮助解释这一点。 我看到说明: x %>%f(y) - > f(x,y) 这个Then符号%>%我不明白有人可以给我一个虚拟指南吗?我真的很难理解这一点。我明白这是这样的: x< - 3,y (或者我也可能错了)。任何人都可以帮助我,并以真正简单的方式向我解释一下吗?感谢提前! P.S。这是使用的示例,我不知道是什么 library(dplyr) hourly_delay< - 航班%>% 过滤器(!is.na(dep_delay))%>% group_by(日期,小时)%>% 总结(delay = mean(dep_delay),n = n())%>% 过滤器(n> 10) / pre> 解决方案你宁愿写: $($) sum(multiply_by(add(1:10,10),2)) 或 1:10%>%add(10)%>%multiply_by (2)%>%sum() ? 在第二个例子中,意图变得更加清晰,它基本相同。通常最容易想到的是定义一些您正在处理的数据对象的第一个表达式( 1:10 ),然后%>%在该数据集上顺序应用一组操作。读取大声, 取数据1:10,然后加10,然后乘以2,然后总和 我们用英语描述操作的方式几乎与我们如何用管道操作员一起写,这是什么使它成为一个很好的工具。 您的示例: 图书馆(dplyr)航班%>%过滤器(!is.na(dep_delay))%>% group_by(日期,小时)%>%总结(delay = mean(dep_delay),n = n())%>%过滤器(n> 10) 我们正在说 采取数据集航班,然后过滤它,所以我们只保留`dep_delay`不为NA的行,然后通过`date`,`hour`列对数据帧进行分组,然后将数据集合(分组变量)与`延迟' 作为`dep_delay`的意思,`n`作为'group'(`n()`)中元素的数量,然后过滤它,所以我们只保留每个组中超过10 个元素的行。 Sorry for a noob question, but I'm new to R and I need help explaining this.I see instruction that: x %>% f(y) -> f(x , y)This "Then" Symbol %>%, I don't get it. Can someone give me a dummy guide for this? I'm having a really hard time understanding this. I do understand it's something like this:x <- 3, y <- 3x (Or I could be wrong here too). Can anyone help me out here and explain it to me in a really-really simple way? Thanks in advance!P.S. Here was the example used, and I've no idea what it islibrary(dplyr)hourly_delay <- flights %>%filter(!is.na(dep_delay)) %>%group_by(date, hour) %>%summarise(delay = mean(dep_delay), n = n()) %>%filter(n > 10) 解决方案 Would you rather write:library(magrittr)sum(multiply_by(add(1:10, 10), 2))or1:10 %>% add(10) %>% multiply_by(2) %>% sum()?The intent is made a lot more clear in the second example, and it's fundamentally the same. It's usually easiest to think of the first expression (1:10) defining some data object you're working on, then %>% applying a set of operations sequentially on that data set. Reading it out loud,Take the data 1:10, then add 10, then multiply by 2, then sumthe way we describe the operation in English is almost identical to how we write it with the pipe operator, which is what makes it such a nice tool.With your example:library(dplyr)flights %>% filter(!is.na(dep_delay)) %>% group_by(date, hour) %>% summarise(delay = mean(dep_delay), n = n()) %>% filter(n > 10)we are sayingTake the data set flights, then Filter it so we only keep rows where `dep_delay` is not NA, then Group the data frame by the `date`, `hour` columns, then Summarize the data set (across grouping variables), with `delay` as the mean of `dep_delay`, and `n` as the number of elements in that 'group' (`n()`), then Filter it so we only keep rows where there were more than 10 elements per group. 这篇关于了解%>%运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!