I am trying to run frame_calendar for my univariate time series data in r. When I try to compute the calendar layout for the data frame, I am getting the following error.
Error in mutate_impl(.data, dots) : Evaluation error: object '72L' not found.
From similar threads, I see the evaluation error: object ' ' not found is usually for an object the users have input in the code. However, in my case, I am not referring to any '72L' in my code. And it is not in my data set as well. Can you please help me figure out how to fix this error? Any help is much appreciated.
Here is a part of my data.
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
Here's my code.
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)
The main problem here is that when you attach()
your data frame first you mask a number of objects that you need. Generally, don't use attach
. If you want to work with an attached data set, use it inside a call to with
, and certainly don't combine this with dplyr
or other tidyverse
functions.
With a clean environment (no data or namespaces attached), use dplyr
methods throughout, like this. Other than not attaching, notice the two other changes to your code. (1) use mutate
to set the Date
column within the dplyr
pipe. (2) x = Hours_Time
, rather than Time
. If you've previously run attach(new_data)
, do detach(new_data)
first, UNTIL you have a clean environment. If you've run it multiple times, you're going to have to detach
multiple times.
library(dplyr)
library(sugrrants)
new_data %>%
mutate(Date = as.Date(Date, origin = "1/1/2000")) %>%
frame_calendar(x = Hours_Time, y = Hourly_Counts, date = Date)
# Date_Time Time Year Month Mdate Day Hours_Time Hourly_Counts Date
# 1 1/1/2015 0:00 0:00:00 2015 January 1 Thursday 1 72 2015-01-01
# 2 1/1/2015 1:00 1:00:00 2015 January 1 Thursday 2 48 2015-01-01
# 3 1/1/2015 2:00 2:00:00 2015 January 1 Thursday 3 53 2015-01-01
# 4 1/1/2015 3:00 3:00:00 2015 January 1 Thursday 4 84 2015-01-01
# 5 1/1/2015 4:00 4:00:00 2015 January 1 Thursday 5 68 2015-01-01
# .Hours_Time .Hourly_Counts
# 1 1.454167 0.6833333
# 2 1.691667 0.0500000
# 3 1.929167 0.1819444
# 4 2.166667 1.0000000
# 5 2.404167 0.5777778
Data:
new_data <- read.table(text = "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", header = TRUE, stringsAsFactors = FALSE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.