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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:04:09+00:00 2026-06-18T06:04:09+00:00

Another novice question regarding big data. I’m working with a large dataset (3.5m rows)

  • 0

Another novice question regarding big data. I’m working with a large dataset (3.5m rows) with time series data. I want to create a data.table with a column that finds the first time the unique identifier appears.

df is a data.table, df$timestamp is a date in class POSIXct, and df$id is the unique numeric identifier. I’m using the following code:

# UPDATED - DATA KEYED
setkey(df, id)
sub_df<-df[,(min(timestamp)), by=list(id)] # Finding first timestamp for each unique ID

Here’s the catch. I’m aggregating over 80k unique ID’s. R is choking. Anything I can do to optimize my approach?

  • 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-18T06:04:11+00:00Added an answer on June 18, 2026 at 6:04 am

    As mentioned by @Arun, the real key (no pun intended) is the use of proper data.table syntax rather than setkey.

    df[, min(timestamp), by=id]
    

    While 80k unique ids sounds like a lot, using the key feature of data.table can make it a manageable prospect.

    setkey(df, id)
    

    Then process as before. For what its worth, you can often use a pleasant side effect of keys which is sorting.

    set.seed(1)
    dat <- data.table(x = sample(1:10, 10), y = c('a', 'b'))
    
        x y
     1:  3 a
     2:  4 b
     3:  5 a
     4:  7 b
     5:  2 a
     6:  8 b
     7:  9 a
     8:  6 b
     9: 10 a
    10:  1 b
    
    setkey(dat, y, x)
    
         x y
     1:  2 a
     2:  3 a
     3:  5 a
     4:  9 a
     5: 10 a
     6:  1 b
     7:  4 b
     8:  6 b
     9:  7 b
    10:  8 b
    

    Then the min or another more complex function is just a subset operation:

    dat[, .SD[1], by=y]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
Okay, Another novice type question. I have this array within the head section on
I want to add the current_user.id from devise to another model... question model: class
another in my beginnerish series of questions about VBA. I am in the process
Another git question... I am in the following situation: A1 ---- B1 ---- C1
Another chapter from the arguments between myself and the other senior developer series :P
Another clipboard question: When text is put onto the clipboard, it frequently goes in
another sql problem of mine .. this time the reader doesn't work properly (
Another question related to this one . I have a List<SortableObjects> that is the
Another jQuery question for you guys. Say I have a url of an image

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.