【问题标题】:error argument "df1" is missing, with no default缺少错误参数“df1”,没有默认值
【发布时间】:2021-11-05 07:02:02
【问题描述】:

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

她发给我的代码:

# 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")

错误:

Error in df(.) : argument "df1" is missing, with no default

【问题讨论】:

  • 您好,您能否提供一个最小的数据样本,以便我们执行代码?然后更容易提供帮助。另外,您是否在此代码 sn-p 之前加载了 ggplot2 和 dplyr?

标签: r


【解决方案1】:

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

df(x, df1, df2, ncp, log = FALSE)

df1 是一个参数。所以错误消息是说 R 找不到 df 函数的第一个参数。

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

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

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

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 2017-12-09
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多