0

I have a tibble df of the form

Province/State      Country/Region       Lat   Long `1/22/20` `1/23/20` `1/24/20` `1/25/20` 
 1 NA                 Afghanistan         33    65        0         0         0         0    
 2 NA                 Albania             41.2  20.2      0         0         0         0         
 3 NA                 Algeria             28.0  1.66      0         0         0         0        
 4 NA                 Andorra             42.5  1.52      0         0         0         0      
 5 NA                 Angola             -11.2  17.9      0         0         0         0
 6 NA                 Antigua and Bar…    17.1 -61.8      0         0         0         0 
 7 NA                 Argentina          -38.4 -63.6      0         0         0         0         
 8 NA                 Armenia             40.1  45.0      0         0         0         0             
 9 Australian Capi…   Australia          -35.5  149.      5         0         0         0              
 10 New South Wales   Australia          -33.9  151.      6         0         0         0       

and I would like to get the total number for each date column for every country like:

Country/Region        `1/22/20` `1/23/20` `1/24/20` `1/25/20` 
 Afghanistan              0         0         0         0    
 Albania                  0         0         0         0         
 Algeria                  0         0         0         0        
 Andorra                  0         0         0         0      
 Angola                   0         0         0         0
 Antigua and Bar…         0         0         0         0 
 Argentina                0         0         0         0         
 Armenia                  0         0         0         0             
 Australia               11         0         0         0

It seems that I would just have to write:

df %>% 
  select(-"Province/State", -"Lat" , -"Long") %>% 
  group_by("Country/Region") %>%
  summarise(sum)

but R keeps throwing the error: Error: Column sum is of unsupported type function; in fact, it does not work for any function.

If instead I use summarise_all, I get: Error in .Primitive("sum")(Country/Region) : invalid 'type' (character) of argument, which is understandable since "Country/Region" is column of characters.

What am I doing wrong? How can I perform this simple computation?

0 Answers0