Need help calculating percent of production by source by 2018 for each continent


I am having trouble calculating the percent of production by source in 2018 for each continent.

df_tidy %>%
group_by (Country, tonnes) %>%


filter (Country % in % c("Africa,Americas,Asia,Europe,Oceania"))

df_tidy<-pivot_wider(data=df_tidy,names_from = c("Africa,Americas,Asia,Europe,Oceania"),values_from =tonnes/sum (df_tidy$tonnes, names_sep = "_"))


Error: Can't subset columns that don't exist. x Column Africa,Americas,Asia,Europe,Oceania doesn't exist.

First of all, please read FAQ: What's a reproducible example (reprex) and how do I create one?

Without actual reprex I can't even guess where your problem actually starts. The error returned, perhaps, because your df_tidy does not have a column titled "Africa,Americas,Asia,Europe,Oceania" (as a single word).

P.S. Consider following some guide for clean code writing (e.g. It is really hard to read and understand.

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.