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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:57:29+00:00 2026-06-10T21:57:29+00:00

I am attempting to assign a column by reference after I subsetted a data.table

  • 0

I am attempting to assign a column by reference after I subsetted a data.table and assigned the return value to another data.table like so (toy example):

> x <- data.table(a=1:10, b=11:20, c=21:30)
> x
     a  b  c
 1:  1 11 21
 2:  2 12 22
 3:  3 13 23
 4:  4 14 24
 5:  5 15 25
 6:  6 16 26
 7:  7 17 27
 8:  8 18 28
 9:  9 19 29
10: 10 20 30
> y <- x[a==1 | a == 2, list(a,b,c)]
> y[,d:=a+b]
Error in `[.data.table`(y, , `:=`(d, a + b)) : 
  It appears that at some earlier point, names of this data.table have been reassigned.     Please ensure to use setnames() rather than names<- or colnames<-. Otherwise, please report     to datatable-help.

I don’t exactly understand the issue: is it that the returned y is simply a “view” into the same memory as x and thus one should copy x before setting a column by reference?

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-10T21:57:31+00:00Added an answer on June 10, 2026 at 9:57 pm

    Unable to reproduce the error with data.table 1.8.2 in R 2.15.1:

    > x <- data.table(a=1:10, b=11:20, c=21:30); x
         a  b  c
     1:  1 11 21
     2:  2 12 22
     3:  3 13 23
     4:  4 14 24
     5:  5 15 25
     6:  6 16 26
     7:  7 17 27
     8:  8 18 28
     9:  9 19 29
    10: 10 20 30
    > 
    >  y <- x[x$a==1 | x$a == 2, list(a,b,c)]
    > 
    > y
       a  b  c
    1: 1 11 21
    2: 2 12 22
    
    > y[,d:=a+b]
       a  b  c  d
    1: 1 11 21 12
    2: 2 12 22 14
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to assign a value to an array object like this: public
I am trying to evaluate two dynamically assigned variables; then attempting to assign a
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to assign a string value to a variable, and then I
I am attempting to insert an int value in a table (RamResults) on a
i'm attempting to cast an object's property as an actual property of another object.
I am attempting to run a pooled logistic regression with panel data and a
Using django-filebrowser and the FileBrowserField I am attempting to assign the directory parameter based
Attempting to deserialize JSON data and update each object's prototype and inherit a common
The situation is, that i need to create table in grid view looking like

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.