Query related to R language to find percentage

A reproducible example, called a reprex would provide a more detailed answer.

Let's take this is pieces.

  1. I assume your data structure is a data frame or a tibble and that rows represent individual employees.
  2. You have classified each employee's start date and end date into a period such as a month or quarter.
  3. You can calculate the number of employees in each department during any time in the quarter by using group_by() and summarize(). See the dplyr page. That's your denominator.
  4. You can similarly calculate the number of employees left standing at the end of the quarter. That your numerator.
> library(scales)
> numerator <- 324
> denominator <- 412
> turnover <- numerator/denominator # as a proportion
> turnover
[1] 0.7864078
> turnover_unformat <- turnover*100
> turnover_unformat
[1] 78.64078
> turnover_pct <- percent(turnover, accuracy = 0.01) # as a percentage to two places
> turnover_pct
[1] "78.64%"
2 Likes