我要遇到了这个问题,已经解决了。
可能是因为你之前处理某列数据时,提示了一些警告,例如, Warning message:
In if (act_slt$session > 45 * 60) act_slt$session <- 45 * 60 : the condition has length > 1 and only the first element will be used(该条件的长度为> 1,并且只使用第一个元素),似乎告诉我们数据有错行、错列问题。
这时候你再用n()就会提示错误:Error: n() should only be called in a data context。
因此,解决的方法是回头检查下警告信息。
但是,有时候library(dplyr),调用summarise,n()是没有问题的。
