Error: Evaluation error: no applicable method

#1
Shanghai_zoo %>%
  mutate(Week = ceiling(day / 7),
         Day_str = factor(weekdays(day, abbreviate = TRUE),
                          levels = c('1', '2', '3', '4', '5', '6', '7'))) %>%
  group_by(year, season, month, Day_str) %>%
  summarize(DayMax = max(Value)) %>%
  ggplot(aes(Week, Day_str, fill = DayMax)) + 
  geom_tile(colour = "white") + 
  facet_grid(Year ~ Month) + 
  scale_fill_gradient2(high = "black", mid ="red", low = "blue") +
  labs(x="Week of Month",
       y="",
       title = "Time-Series Calendar Heatmap", 
       subtitle="Chengdu - PM2.5 level", 
       fill = "PM2.5 level")

It appears error following:

Error: Evaluation error: no applicable method for 'weekdays' applied to an object of class "c('integer', 'numeric')".

So should i paste my dataset here?

0 Likes

#2

From the weekdays() documentation, it sounds like the first argument (in your case, day, needs to be "inheriting from class POSIXt or Date."

Arguments

x an object inheriting from class "POSIXt" or "Date" .

abbreviate logical vector (possibly recycled). Should the names be abbreviated?

origin an length-one object inheriting from class "POSIXt" or "Date" .

arguments for other methods

Could you turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

0 Likes

closed #3

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes