我正在尝试为r中的单变量时间序列数据运行frame_calendar . 当我尝试计算数据框的日历布局时,我收到以下错误 .
mutate_impl(.data,dots)出错:评估错误:找不到对象'72L' .
从类似的线程,我看到评估错误:找不到对象''通常是用户在代码中输入的对象 . 但是,就我而言,我的代码中并没有提到任何'72L' . 它也不在我的数据集中 . 能帮我解决一下如何解决这个错误吗?任何帮助深表感谢 .
这是我数据的一部分 .
Date_Time Time Date Year Month Mdate Day Hours_Time Hourly_Counts
1/1/2015 0:00 0:00:00 2015-01-01 2015 January 1 Thursday 1 72
1/1/2015 1:00 1:00:00 2015-01-01 2015 January 1 Thursday 2 48
1/1/2015 2:00 2:00:00 2015-01-01 2015 January 1 Thursday 3 53
1/1/2015 3:00 3:00:00 2015-01-01 2015 January 1 Thursday 4 84
1/1/2015 4:00 4:00:00 2015-01-01 2015 January 1 Thursday 5 68
这是我的代码 .
newdata <- read.csv("D:/NEWDATA.csv")
attach(newdata)
View(newdata)
newdata[,3] <- as.Date(Date, origin = "1/1/2000")
attach(newdata)
View(newdata)
library(dplyr)
# compute the calendar layout for the data frame
calendar_df <- newdata %>%
filter(Year == 2015) %>%
frame_calendar(x = Time, y = Hourly_Counts, date = Date)
1 回答
这里的主要问题是,当您首先使用数据框时,您需要屏蔽许多对象 . 通常,请勿使用
attach
. 如果要使用附加数据集,请在调用with
时使用它,当然不要将其与dplyr
或其他tidyverse
函数结合使用 .使用干净的环境(没有附加数据或名称空间),请使用
dplyr
方法,如下所示 . 除了不附加,请注意代码的其他两个更改 . (1)使用mutate
在dplyr
管道中设置Date
列 . (2)x = Hours_Time
,而不是Time
. 如果您以前运行attach(new_data)
,请首先执行detach(new_data)
,直到您拥有干净的环境 . If you've run it multiple times, you're going to have to detach multiple times.数据: