我的一个朋友正在使用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发布于 2021-11-05 07:39:01
在控制台中输入?df,您将看到df是一个带有以下参数的函数。
df(x, df1, df2, ncp, log = FALSE)其中df1是一个参数。因此,错误消息是R找不到df函数的第一个参数。
在这个代码示例中,您的朋友尝试将一个名为df的数据框放入dplyr包中的filter函数和ggplot2包中的ggplot函数中,以创建一个图。
所以我猜你的朋友需要将df定义为一个数据框架。否则,R会认为df是一个函数,并不断抛出错误。
顺便说一下,因为df是在R中定义的函数,所以它不是一个数据帧的好名字。然而,人们一直使用df作为数据框的名称。下次尝试使用不同的名称作为数据框的名称,例如dat。
https://stackoverflow.com/questions/69849609
复制相似问题