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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:47:18+00:00 2026-06-06T02:47:18+00:00

I encountered the following problem after upgrading to the latest version 1.8.1 of data.table

  • 0

I encountered the following problem after upgrading to the latest version 1.8.1 of data.table (available on R-forge). Up to that version, I could do this:

DT = data.table(a=LETTERS[c(1,1:3)],b=4:7,key="a")
DT
   a b
1: A 4 
2: A 5
3: B 6
4: C 7

DT[ ,newcol := NA]

i.e. I was able to add a new column filled with NAs. Now I get an error saying that the logical type of NA is not supported (in fact DT[ ,newcol := TRUE] doesn’t work either).

So right now I work around that by first adding an double column, and then setting that to NA or whatever logical I need:

DT[ ,newcol:=1]
a b newcol
1: A 4      1
2: A 5      1
3: B 6      1
4: C 7      1

and

DT[ ,newcol:=NA]
a b newcol
1: A 4      NA
2: A 5      NA
3: B 6      NA
4: C 7      NA

I wanted to ask whether this is the right way to do this. It’s not a big deal I guess. It’s working fine like that, just wanted to avoid unnecessary steps.

  • 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-06T02:47:19+00:00Added an answer on June 6, 2026 at 2:47 am

    Until this bug is fixed (see Matthew Dowle’s comment above), you can get around it by directly specifying the type of NA that you want in the new column (except of course for “logical”, which is the type that doesn’t work at the moment):

    DT <- data.table(a=LETTERS[c(1,1:3)],b=4:7,key="a")
    DT[ ,newcol := NA_real_]  ## Other options are NA_integer_ and NA_character_ 
    #    a b newcol
    # 1: A 4     NA
    # 2: A 5     NA
    # 3: B 6     NA
    # 4: C 7     NA
    
    ## Plain old NA has type and class "logical", partly explaining the 
    ## error message returned by DT[,newcol:=NA]
    c(typeof(NA), class(NA))
    # [1] "logical" "logical"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After upgrading all my Maven plugins version for a project, I encountered the following
I have the following problem that other people must have encountered. I am working
I am in the process of changing my git-merge-workflow and encountered following problem: Up
I've encountered the following problem with jLine. We open the command prompt (both linux
More than one time I have encountered the following problem when building code with
I'm learning C# and I encountered the following problem. I have two classes: base
While making AutoHotkey-script I encountered the following problem. I need navigate listbox (one position
I am just starting working with jquery and have encountered the following problem <div
while designing my user control, i encountered the following problem: i would like to
I encountered a problem dealing with UTF-8, XML and Perl. The following is the

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.