0

So, my code below was working at some point but it is no longer working.

This is my code:

new_plot <- data_set %>%
  group_by("County") %>%
  select("people_vaccinated") %>%
  Date == "2021-02-11"
exists("County")
new_plot

ggplot(new_plot, mapping = aes(x= County, y = people_vaccinated)) +
  geom_bar()

At one point, this was working completely fine but I must have messed something up here or earlier for it to not work, because I keep getting "County" not found. I used exists() to find if my variable exists, which it most certainly does in data_set, but it just keeps returning "Error in FUNC(x[[I]], ...) : object 'County' not found. It worked before and I was so happy with it, now I don't know what to do about it. Can anyone tell me what I am doing wrong?

orangetaco
  • 33
  • 1
  • 1
  • 3
  • That isn't reasonable R code: `%>% Date == "2021-02-11"` seems like you want `%>% filter(Date == "2021-02-11")` instead. (I'd think you'd get an error `could not find function "Date"` ... unless you have a function named `Date` somewhere ... I don't.) – r2evans Mar 22 '21 at 14:25
  • FYI, I'm inferring from your code that `Date` is a string but it really resembles dates (which are number-like). If you're ever going to plot based on `Date`, you need to convert it to the proper class using `Date = as.Date(Date)` so that its numeric properties will plot properly. (If/when you get to that point, see https://stackoverflow.com/q/56557922/3358272, https://stackoverflow.com/q/65647998/3358272, https://stackoverflow.com/q/66606315/3358272.) – r2evans Mar 22 '21 at 14:28
  • And last, while I suspect that @Sirius' answer will resolve your immediate issues, it would be much easier to help if we had a sample of your data. Please [edit] your question and add sample data from one of: (1) normal R dataset, e.g., `mtcars`, `diamonds`, etc; (2) programmatic build, such as `data.frame(...)` (using `set.seed` if random); (3) unambiguous data with `dput(head(x,10))` (where "10" is something meaningful); or (4) a URL. Note I did not suggest copying how a frame looks on the console, it can be ambiguous. (See https://stackoverflow.com/q/5963269) – r2evans Mar 22 '21 at 14:31

1 Answers1

0

There's a couple of things that are off with your code sample.

  1. change to group_by(County) without the quotes
  2. Date == "2021-02-11" makes no sense the way its used, did you mean: filter( Date == "2021-02-11" ) ?
Sirius
  • 5,224
  • 2
  • 14
  • 21