You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言使用dplyr时出现‘找不到函数"%.%"’错误,新手求助

解决dplyr中%.%函数找不到的错误

Hey there! Let's break down what's going on here and fix that error quickly.

错误原因

The %.% operator was used in very old versions of dplyr (pre-0.4.0, which is outdated now). Modern dplyr (version 1.0.0+) uses the %>% pipe operator instead. Since you're loading a current version of dplyr, R can't locate the outdated %.% function, which causes the error you're seeing.

修正后的代码

You have two solid options to fix this:

Option 1: Use dplyr's %>% pipe (most widely used)

Replace all instances of %.% with %>%. Here's your updated code:

library(MASS)
library(dplyr)

painters %>% 
  group_by(school) %>% 
  mutate(Len = n()) %>% 
  filter(Len > 6)

Option 2: Use R's native |> pipe (R 4.1.0+)

If you're using a newer version of R (4.1.0 or later), you can use the built-in pipe operator |> instead—no extra setup needed beyond loading your required packages:

library(MASS)
library(dplyr)

painters |> 
  group_by(school) |> 
  mutate(Len = n()) |> 
  filter(Len > 6)

Quick tip for new R users

Both pipe operators do the same core job: they pass the result from the left side of the pipe into the first argument of the function on the right. This makes your code way easier to read and follow, compared to nesting functions inside each other.

If you want to confirm your dplyr version, run this command:

packageVersion("dplyr")

You should see a version number like ‘1.1.0’ or higher—all these versions use %>% (or |>) instead of the old %.%.

内容的提问来源于stack exchange,提问作者user1652926

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:16:07