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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:35:04+00:00 2026-06-11T14:35:04+00:00

I have the following data.table in R : library(data.table) DT = data.table(x=rep(c(b,a,c),each=3), y=sample(rnorm(9)), v=1:9)

  • 0

I have the following data.table in R:

  library(data.table)
  DT = data.table(x=rep(c("b","a","c"),each=3), y=sample(rnorm(9)), v=1:9)

I just want to compute the minimum and the maximum by the column x and add these two new columns to DT. Here is my line for this:

  DT[,c("e","d"):= list(min(y),max(y)), with=FALSE, by = x] 
  Error in `[.data.table`(DT, , `:=`(c("e", "d"), list(min(y), max(y))),  : 
  'with' must be TRUE when 'by' or 'keyby' is provided

Nonetheless, if I write: DT[,c("e","d"):= list(min(y),max(y)), with=FALSE], I get this:

     x       y    v     e       d
  1: a -1.7125000 4 -1.7125 1.30553
  2: a  1.0198038 5 -1.7125 1.30553
  3: a  1.3055301 6 -1.7125 1.30553
  4: b -0.9238759 1 -1.7125 1.30553
  5: b  0.3077016 2 -1.7125 1.30553
  6: b -1.2580845 3 -1.7125 1.30553
  7: c -0.9399120 7 -1.7125 1.30553
  8: c -0.1910583 8 -1.7125 1.30553
  9: c  0.1239158 9 -1.7125 1.30553

As you can see, this is working but it’s not doing the task by x. I want to obtain something similar but e and d are supposed to be computed by each value of the variable x. So, my question is: How can I solve this?

  • 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-11T14:35:06+00:00Added an answer on June 11, 2026 at 2:35 pm

    “:= by group” (new in version 1.8.2) and “:= with multiple new columns” (new in version 1.7.8) are both relatively recent additions to data.table.

    “:= by group with multiple new columns” just hasn’t (yet) been implemented.

    So for now, you can either do this (if you want a one-liner):

    setkey(DT, "x")
    DT <- DT[DT[,list(e=min(y), d=max(y)), by=key(DT)]]
    

    or this (if you want to minimize extra copying operations):

    setkey(DT, "x")
    DT[,e:=min(y), by=key(DT)]
    DT[,d:=max(y), by=key(DT)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following data.table in R : library(data.table) DT = data.table(x=rep(c(b,a,c),each=3),
My table column contains following sample data: /Users/abct2/Library/Application Support/iPhone Simulator/4.3/Applications/FD301781-D39F-469E-A604-8164CC9A4493/Library/Caches/List3-ROHAN TEST1/word_306:24:50.jpg Now, I want
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have a table RDCAlerts with the following data in a column of type
I have a table that includes the following column: mytable <- data.frame(beta_0 = c(1,2,3)
I have the following data.frame: sample <- data.frame(day=c(1,2,5,10,12,12,14)) sample.table <- as.data.frame(table(sample$day)) Now what I'd
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have the following data on a table tbl Admission : Date and Time
Suppose we have the following table data: ID parent stage submitted 1 1 1
Lets say i have a table with the following data Customer table: Name amount

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.