-1

I have a table which I want to show aggregate . It’s pretty straightforward when it’s sum. I can use janitor to show total . But in my case I want to calculate rates.how can that be done.

Language Files   Overall
1      C++  4009 15328
2     Java   210   876
3   Python    35   200

Now if I want to add a new column rate which is files/ overall how can I calculate the rate for total row . It should be sum of files by sum of overall . I am unable to figure out how to do that for the total row field. Expected output

       Files   LOC Rate
C++     4009 15328 40.0
Java     210   876 23.3
Python    35   200 17.5
Total   4254 16404 25.93
SNT
  • 1,283
  • 3
  • 32
  • 78
  • This is a new column . My question was how to add a new row call total where I want to show df$rates value too. Apologies if my original question wasn’t clear – SNT May 19 '20 at 03:49
  • updated the ordinal post – SNT May 19 '20 at 03:54

1 Answers1

2

You can use :

transform(janitor::adorn_totals(df), Rate = Files/Overall * 100)

#  Language Files Overall   Rate
#1      C++  4009   15328 26.155
#2     Java   210     876 23.973
#3   Python    35     200 17.500
#4    Total  4254   16404 25.933

data

df <- structure(list(Language = c("C++", "Java", "Python"), Files = c(4009L, 
210L, 35L), Overall = c(15328L, 876L, 200L)), row.names = c(NA, 
-3L), class = "data.frame")
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213