Columns with boolean logic in count()

I am VERY new to R so please forgive if this is a stupid question. I am attempting a pretty basic calculation to count the total of rows on certain conditions and grouping them by year. I created a data frame in order to organize this and create a plot, but two values show up for each year - one if the condition is true and one if it is false. This includes columns with boolean values that I have attempted to use as a filter - with and without quotations marks around TRUE.

The columns with the boolean values are the full names for the conditions within the filter function, which is why it looks so weird. But despite re-running the entire code, the correct values are still not filtered. The plot that came out of the bottom code was predictably useless.

I have also tried filtering within the plot to no avail. It doesn't help that the number that count as TRUE seem too low. Any idea what the issue could be and what I could be missing?

I think what you want is code like this:

spc_stats |> 
  filter(st %in% c("AL","LA","MS","AR","TN","GA")) |> 
  group_by(yr,st) |> 

Looking at the later part of your code, I don't think you want to so a left_join. If I understand your data correctly, you will get many more rows than you want. It might make more sense to not filter the original data by state, summarize all of the states and then label each state as belonging to either the d_total or t_total category.

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.