【发布时间】:2019-03-22 19:31:19
【问题描述】:
我是 R 新手,正在学习 DataQuest 的 R 课程。我有一个森林火灾的csv。该文件可以在这里下载:
https://archive.ics.uci.edu/ml/machine-learning-databases/forest-fires/
我想创建一个按“x”(例如月或日)对数据进行分组并返回计数条形图的函数。
library(readr)
library(dplyr)
library(ggplot2)
forestFires <- read_csv("forestfires.csv")
forestFiresCountPlot <- function(x) {
forestFiresGroup <- forestFires %>%
group_by(x) %>%
summarise(n(x)) %>%
ggplot(data = forestFiresGroup) +
aes(x = x, y = n(x)) +
geom_bar()
}
forestFiresMonth <- forestFiresCountPlot(month)
forestFiresDay <- forestFiresCountPlot(day)
# Output - Error: Column `x` is unknown
当我调用函数时,如何声明月份和日期是列?
【问题讨论】: