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

How to pivot data in R?

$
0
0

I have a data set as I've shown below:

df <- tribble(
  ~id,  ~clicks,       
  "1",    10,    
  "2",     5,    
  "3",     7,    
  "4",     6,    
  "5",     3,    
  "6",     4,    
  "7",     5,    
  "8",     6,    
  "9",     1,    
  "10",    9,   
)

Now, I want to set an interval from id column for the columns and then sum the rows for each interval. Simply, here is my desired data:

desired_df <- tribble(
  ~"1-2",   ~"2-5",    ~"5-10""26.7%",  "28.5%",   "44.6%"
)

How can I get the desired data?


Viewing all articles
Browse latest Browse all 201919

Trending Articles



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