Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201941

How to calculate share rate in R?

$
0
0

I have a dataset as I've shown below:

data <- tribble(
  ~id,     ~click,  ~engagement,
   1,         1,          0,
   2,         2,          3,         
   3,         3,          5,
   4,         4,          6, 
   5,         5,          2,
   6,         3,          4,
   7,         8,          7,
   8,         6,          1,
   9,         7,          6,
  10,         7,          3,
)

My desired data is something like this:

new_data <- tribble(
  ~total_click,  ~total_engagement, ~percantage_click, ~percantage_engagement, 
     46,              37,              0.5542169,          0.4457831,
)

I was able to get total_click and total_engagement by coding like this:

data %>% 
  summarise(total_click = sum(click), total_engagement = sum(engagement)) 

How can I get the percentage?


Viewing all articles
Browse latest Browse all 201941

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>