I'm trying to divide two columns via month by amount grouped by their region.
My dataset looks like this:
month   Amount  Region
10      2       APAC
20      5       EMEA
10      3       APAC
10      4       NA
4       3       NA
I have tried the below code however it gives me incorrect answer
a <- t(aggregate(data$month/data$Amount, by=list(region=data$Region), FUN=sum))
I get the below results:
       [,1]       [,2]       [,3]      
region "APAC"     "EMEA"     "NA"      
x      "8.333333" "4.000000" "3.833333"
The desired output is:
       [,1]       [,2]       [,3]      
region "APAC"     "EMEA"     "NA"      
x      "4            "4"      3"
However it is incorrect. Can anyone tell where am I going wrong?
 
     
    