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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:00:15+00:00 2026-06-07T11:00:15+00:00

Due to time constraints, I’ve decided to use data tables in my code instead

  • 0

Due to time constraints, I’ve decided to use data tables in my code instead of data frames, as they are much faster. However, I still want the functionality of data frames. I need to merge two data tables, conserving all values (like setting all=TRUE in merge).

Some example code:

> x1 = data.frame(index = 1:10)
> y1 = data.frame(index = c(2,4,6), weight = c(.2, .5, .3))
> x1
   index
1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10    10
> y1
  index weight
1     2    0.2
2     4    0.5
3     6    0.3

> merge(x,y, all=TRUE)
      index weight
 [1,]     1     NA
 [2,]     2      1
 [3,]     3     NA
 [4,]     4      2
 [5,]     5     NA
 [6,]     6      3
 [7,]     7     NA
 [8,]     8     NA
 [9,]     9     NA
[10,]    10     NA

Now can I do a similar thing with data tables? (The NA’s don’t necessarily have to stay, I change them to 0’s anyways).

> x2 = data.table(index = 1:10, key ="index")
> y2 = data.table(index = c(2,4,6), weight= c(.3,.5,.2))

I know you can merge, but I also know that there is a faster 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-07T11:00:18+00:00Added an answer on June 7, 2026 at 11:00 am

    so following on from Translating SQL joins on foreign keys to R data.table syntax

    x2 = data.table(index = 1:10, key ="index")
    y2 = data.table(index = c(2,4,6), weight= c(.3,.5,.2),key="index")
    y2[J(x2$index)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using Socket.IO to communicate real-time statistics to connected browsers; however due to
I'm developing an Android app, and due to time circumstances, I started developing the
Due to lack to time i cannot dig google and get information about openid
I've lost some time with a bug in my app due to user authentication.
I am converting the current date to GMT time. The result is in-consistent, due
Due to legacy reasons a lot of our data is stored encoded in standard
I'm using Solr with Sunspot (ruby) and due to other constraints i have to
I have a huge database with many constraints and I have updated some data
I have a slightly outdated experimental branch, that was pushed aside due to time
Due to a sad situation I receive HTML like this: <p>Perform the following commands:

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.