Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:51:30+00:00 2026-06-03T23:51:30+00:00

I have a data frame like so product_id view_count purchase_count 1 11 1 2

  • 0

I have a data frame like so

product_id view_count purchase_count
1           11         1   
2           20         3
3           5          2
...

I would like to transform this into a table that groups by view_count and sums the purchase_count for an interval for instance.

view_count_range total_purchase_count
0-10                 45
10-20                65

These view_count_ranges will be of fixed size. I would appreciate any suggestions on how to group ranges like this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:51:31+00:00Added an answer on June 3, 2026 at 11:51 pm

    cut is a handy tool for this sort of thing. here’s one way:

    #First make some data to work with 
    #I suggest you do this in the future as it makes it 
    #easier to provide you with assistance.
    set.seed(10)
    dat <- data.frame(product_id=1:15, view_count=sample(1:20, 15, replace=T), 
        purchase_count=sample(1:8, 15, replace=T))
    dat   #look at the data
    
    #now we can use cut and aggregate by this new variable we just created
    dat$view_count_range <- with(dat, cut(view_count, c(0, 10, 20)))
    aggregate(purchase_count~view_count_range, dat, sum)
    

    Which yields:

      view_count_range purchase_count
    1           (0,10]             39
    2          (10,20]             31
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a data.frame that looks like this > head(df) Memory Memory Memory Memory
I have a data frame that looks like this: user1,product1,0 user1,product2,2 user1,product3,1 user1,product4,2 user2,product3,0
I have a data.frame that looks like this. x a 1 x b 2
i have a data frame that contains a data like this : V1 V2
Suppose, you have a data.frame like this: x <- data.frame(v1=1:20,v2=1:20,v3=1:20,v4=letters[1:20]) How would you select
I have a data.frame that looks like this: 320 Dutch A7 3 321 Dutch
I have a data frame that looks like this: site date var dil 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.