在r中的unique()函数中使用管道不起作用 [英] Using the pipe in unique() function in r is not working

查看:64
本文介绍了在r中的unique()函数中使用管道不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用具有唯一功能的管道运算符(%>%)时,我会遇到一些麻烦.

I have some troubles using the pipe operator (%>%) with the unique function.

df = data.frame(
  a = c(1,2,3,1),
  b = 'a')

unique(df$a) # no problem here
df %>% unique(.$a) # not working here
# I got "Error: argument 'incomparables != FALSE' is not used (yet)"

有什么主意吗?

推荐答案

如其他答案所述: df%>%unique(.$ a)等同于 df%>%unique(.,.$ a).

As other answers mention : df %>% unique(.$a) is equivalent to df %>% unique(.,.$a).

要强制显示点,您可以执行以下操作:

To force the dots to be explicit you can do:

df %>% {unique(.$a)}
# [1] 1 2 3

magrittr

df %$% unique(a)
# [1] 1 2 3

或者可能说出明显的内容:

Or possibly stating the obvious:

df$a %>% unique
# [1] 1 2 3

这篇关于在r中的unique()函数中使用管道不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆