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 9017837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:22:22+00:00 2026-06-16T04:22:22+00:00

UPDATED AND SIMPLIFIED I am having a really large table (~ 7 million records)

  • 0

UPDATED AND SIMPLIFIED

I am having a really large table (~ 7 million records) which has the following structure.

temp <- read.table(header = TRUE, stringsAsFactors=FALSE,
                   text = "Website Datetime    Rating
A 2007-12-06T14:53:07Z        1
A 2006-07-28T03:52:26Z        4
B 2006-11-02T11:06:25Z        2
C 2007-06-19T06:56:08Z        5
C 2009-11-28T22:27:58Z        2
C 2009-11-28T22:28:13Z        2")

What I want to retrieve is the unique websites with a max rating per website:

Website    Rating
A    4
B    2
C    5

I tried using a for loop but it was too slow. Is there any other way I can achieve 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-16T04:22:23+00:00Added an answer on June 16, 2026 at 4:22 am

    I would probably explore the data.table package, though without more details, the following example solution is most likely not going to be what you need. I mention this because, in particular, there might be more than one “Rating” record per group which matches max; how would you like to deal with those cases?

    library(data.table)
    temp <- read.table(header = TRUE, stringsAsFactors=FALSE,
                    text = "Website Datetime    Rating
                            A       2012-10-9   10
                            A       2012-11-10  12
                            B       2011-10-9   5")
    DT <- data.table(temp, key="Website")
    DT
    #    Website   Datetime Rating
    # 1:       A  2012-10-9     10
    # 2:       A 2012-11-10     12
    # 3:       B  2011-10-9      5
    DT[, list(Datetime = Datetime[which.max(Rating)], 
              Rating = max(Rating)), by = key(DT)]
    #    Website   Datetime Rating
    # 1:       A 2012-11-10     12
    # 2:       B  2011-10-9      5
    

    I would recommend that to get better answers, you might want to include information like how your datetime variable might factor into your aggregation, or whether it is possible for there to be more than one “max” value per group.

    If you want all the rows that match the max, the fix is easy:

    DT[, list(Time = Times[Rating == max(Rating)], 
              Rating = max(Rating)), by = key(DT)]
    

    If you do just want the Rating column, there are many ways to go about this. Following the same steps as above to convert to a data.table, try:

    DT[, list(Datetime = max(Rating)), by = key(DT)]
         Website Datetime
    # 1:       A        4
    # 2:       B        2
    # 3:       C        5
    

    Or, keeping the original “temp” data.frame, try aggregate():

    aggregate(Rating ~ Website, temp, max)
        Website Rating
    # 1       A      4
    # 2       B      2
    # 3       C      5
    

    Yet another approach, using ave:

    temp[with(temp, Rating == ave(Rating, Website, FUN=max)), ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED: I am setting default scope for some models in a runtime which seems
UPDATED: I have some table with sync_numbers, like this: --------------------- id | sync_number ---------------------
I have table of user actions, each having a user associated, a type, and
I'm having trouble with one of my sites on which two ajax requests are
Having a problem with TFS and TFS CI in the following scenario (I have
Here is a simplified table structre for what I am trying to do: T1:
I'm having issues with keyboard navigation in my wpf application. Simplified I have a
I've got a table of crime data. In a simplified version, it would look
I am having issues with character encoding. I have simplified it to this below
I have an asp web service that contains a class which has a function

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.