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

  • Home
  • SEARCH
  • 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 8256943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:02:20+00:00 2026-06-08T02:02:20+00:00

When using the data.table package, I am a bit unsure of when i need

  • 0

When using the data.table package, I am a bit unsure of when i need to setkey(). For example, when using the := operator with the by option, things seem to still be very fast even though I have not set a key. Could someone please elucidate when setkey() is necessary and when it is not? And if it is not necessary prior to calling := with by then how is the data.table package so fast since presumably it has to do the same thing as apply in standard data.frame R by doing a sequential search rather than a binary one since it doesn’t know whether my data.table is actually sorted by the argument to by.

Thanks

  • 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-08T02:02:23+00:00Added an answer on June 8, 2026 at 2:02 am

    These 2 FAQs seem close :

    3.2 I don’t have a key on a large table, but grouping is still really quick. Why is that?
    data.table uses radix sorting. This is signicantly faster than other sort algorithms. Radix is specifically for integers only, see ?base::sort.list(x,method="radix"). This is also one reason why setkey is quick. When no key is set, or we group in a different order from that of the key, we call it an ad hoc by.

    3.3 Why is grouping by columns in the key faster than an ad hoc by?
    Because each group is contiguous in RAM, thereby minimising page fetches, and memory can be copied in bulk (memcpy in C) rather than looping in C.

    What it doesn’t say, and probably should do, is that you need a very large dataset, where each group is also very large, before you notice the difference between keyed by and ad hoc by. Something like 100 groups of 100MB each (a 10GB data.table) such as 1e8 rows and 13 columns. Otherwise, there is no need to setkey first, especially since that can get onerous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using data.table package quite a bit. There are lots of examples of
I can easy export table data by using DBMS_XMLGEN. But is there a package
Using a data table from http://datatables.net/ , How can i stop it from overflowing
I am trying to import an excel file into a data table using GemBox
I am using a Windows application for exporting a data table to Excel. It's
I've noticed some inconsistent (inconsistent to me) behaviour in data.table when using different assignment
I'm using MyFaces 1.1.7 with Facelets and Tomahawk. When creating a regular data table,
I'm trying to reset some input text fields, inside of a data table, using
Im using prawn to create pdfs that contain much data in table format and
I am trying to convert following table data into nested array using PHP. I

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.