首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误参数"df1“缺失,没有默认值

错误参数"df1“缺失,没有默认值
EN

Stack Overflow用户
提问于 2021-11-05 07:02:02
回答 1查看 175关注 0票数 1

我的一个朋友正在使用r语言,她问我她做错了什么,我似乎找不到问题所在。有人知道这是什么吗?

她发给我的代码:

代码语言:javascript
复制
# 10*. Pipe that to a ggplot command and create a histogram with 4 bins. 
# Hint: you will NOT write ggplot(df, aes(...)) because the df is already piped in. 
# Instead, just write: ggplot(aes(...)) etc.
# Title the histogram, "Distribution of Sunday tips for bills over $20"
# Feel free to style the plot (not required; this would be a typical exploratory
# analysis where only you will see it, so it doesn't have to be perfect).
df %>%
  filter(total_bill > 20 & day == "Sun") %>%
  ggplot(aes(x=total_bill, fill=size)) +
    geom_histogram(bins=4) +
    ggtitle("Distribution of Sunday tips for bills over $20")

错误:

代码语言:javascript
复制
Error in df(.) : argument "df1" is missing, with no default
EN

回答 1

Stack Overflow用户

发布于 2021-11-05 07:39:01

在控制台中输入?df,您将看到df是一个带有以下参数的函数。

代码语言:javascript
复制
df(x, df1, df2, ncp, log = FALSE)

其中df1是一个参数。因此,错误消息是R找不到df函数的第一个参数。

在这个代码示例中,您的朋友尝试将一个名为df的数据框放入dplyr包中的filter函数和ggplot2包中的ggplot函数中,以创建一个图。

所以我猜你的朋友需要将df定义为一个数据框架。否则,R会认为df是一个函数,并不断抛出错误。

顺便说一下,因为df是在R中定义的函数,所以它不是一个数据帧的好名字。然而,人们一直使用df作为数据框的名称。下次尝试使用不同的名称作为数据框的名称,例如dat

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69849609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档