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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:53:23+00:00 2026-05-28T13:53:23+00:00

I am using data.table package quite a bit. There are lots of examples of

  • 0

I am using data.table package quite a bit. There are lots of examples of subsetting or querying or searching (or whatever you want to call it) with a binary search which is apparently much faster than a vector scan. Here is an excerpt from the help file.

DT["a"]                    # binary search (fast)
DT[x=="a"]                 # vector scan (slow)

But what happens if the the columns one wants to search on is not a factor (or character) but rather is an integer.

cpt <- c(23456,23456,10000,44555,44555)
description <- c("tonsillectomy","tonsillectomy in >12 year old","brain transplant","castration","orchidectomy")
cpt.desc <- data.table(cpt,description)

setkey(cpt.desc,cpt)
cpt.desc[10000,]  

That does not work because the integer 10000 is interpreted as the 10000th row which in this data.table does not exist.

If we modify the syntax then we get what we are looking for.

cpt.desc[cpt==10000,]

However that looks a lot as if it is the slow vector scan method. Is there a binary search function for integers in the data.table package? Thanking you in anticipation of your help.

  • 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-05-28T13:53:24+00:00Added an answer on May 28, 2026 at 1:53 pm

    Try cpt.desc[J(10000)]. Add ,"mult=all" to get all the matches.

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

Sidebar

Related Questions

I can easy export table data by using DBMS_XMLGEN. But is there a package
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'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
I'm using System.Data.OracleClient.OracleCommand to create a table and fill it out with some data.
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I was trying to load a data file into mysql table using LOAD DATA
I have a script that I am using to copy data from a table
I am using VSTO to fill data into a table in a Microsoft Word

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.