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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:42:04+00:00 2026-06-13T09:42:04+00:00

I am trying to exclude some rows from a datatable based on, let’s say,

  • 0

I am trying to exclude some rows from a datatable based on, let’s say, days and month – excluding for example summer holidays, that always begin for example 15th of June and end the 15th of next month. I can extract those days based on Date, but as as.Date function is awfully slow to operate with, I have separate integer columns for Month and Day and I want to do it using only them.

It is easy to select the given entries by

DT[Month==6][Day>=15]
DT[Month==7][Day<=15]

Is there any way how to make “difference” of the two data.tables (the original ones and the ones I selected). (Why not subset? Maybe I am missing something simple, but I don’t want to exclude days like 10/6, 31/7.)

I am aware of a way to do it with join, but only day by day

setkey(DT, Month, Day)
DT[-DT[J(Month,Day), which= TRUE]]

Can anyone help how to solve it in more general way?

  • 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-13T09:42:05+00:00Added an answer on June 13, 2026 at 9:42 am

    Great question. I’ve edited the question title to match the question.

    A simple approach avoiding as.Date which reads nicely :

    DT[!(Month*100L+Day) %between% c(0615L,0715L)]
    

    That’s probably fast enough in many cases. If you have a lot of different ranges, then you may want to step up a gear :

    DT[,mmdd:=Month*100L+Day]
    from = DT[J(0615),mult="first",which=TRUE]
    to = DT[J(0715),mult="first",which=TRUE]
    DT[-(from:to)]
    

    That’s a bit long and error prone because it’s DIY. So one idea is that a list column in an i table would represent a range query (FR#203, like a binary search %between%). Then a not-join (also not yet implemented, FR#1384) could be combined with the list column range query to do exactly what you asked :

    setkey(DT,mmdd)
    DT[-J(list(0615,0715))]
    

    That would extend to multiple different ranges, or the same range for many different ids, in the usual way; i.e., more rows added to i.

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

Sidebar

Related Questions

I'm trying to exclude some data from a string using regex. var match =
I'm using MVC 3, and I'm trying to exclude some fields from validation in
I'm trying to exclude selected rows based on the first letter of a column.
I am trying to sort an xml using xsl. Got some sample from xml.com.
I'm trying to collect some information from a Atom formatted feed and display it
I'm trying to export the data from MS Excel sheet to a datatable using
I've been trying to exclude an asp.net web control from the tabbing order. The
trying to exclude some spring dependencies, using the following require: - play - com.openadex.jupiter
I'm trying to exclude some internal IP addresses and some internal IP address formats
I am trying to pull some data from a Postgres database to implement a

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.