r - 将数据框通过管道传递给一个函数,该函数的参数通过管道传递一个点

标签 r lambda dplyr magrittr

如何将数据帧传送到其参数传送点的函数?

mpg %>% rbind(., . %>% rev())

Error in rep(xi, length.out = nvar) : attempt to replicate an object of type 'closure'

另一个例子:

mpg %>%
  {
    . %>% arrange(manufacturer)
  }

Functional sequence with the following components:

  1. arrange(., manufacturer)

Use 'functions' to extract the individual functions.

最佳答案

将要通过管道传输的点括在括号中,例如 (.):

mpg %>% rbind(., (.) %>% rev())

或者,对于 lambda 函数:

mpg %>%
  {
    (.) %>% arrange(manufacturer)
  }

关于r - 将数据框通过管道传递给一个函数,该函数的参数通过管道传递一个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757191/

相关文章:

r - R 中的文本分析 - 词频

r - 在 sqldf 中将整数值转换为日期时间

java - 如何使用 Java lambdas 收集新类型列表中的元素?

r 获取序列的第二次出现

r - 如何在 R 中按名称获取最多嵌套列表值

r - 将所有相似的列表合并到一个列表列表中

r - 在 R markdown 中隐藏评论

java - 将列表转换为 map

c# - 如何使用反射在运行时构建此 c# "Expression"?

r - 在R中简洁地创建一个区间变量