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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:41:24+00:00 2026-05-25T03:41:24+00:00

I’m looking for advice on how to subtract values from each other listed in

  • 0

I’m looking for advice on how to subtract values from each other listed in two data frames. In the example below with the two data frames A and B, I would like to subtract the values of the 2nd columns from each other on the condition that the first column vectors are matching. For example, when vector X1 is R1 then 5.1 – 5 and 4.8 – 5.

A<-data.frame(cbind(c(‘R1′,’R1′,’R2′,’R4′,’R4′,’R4’),c(5.1,4.8,4.9,5.0,5.0,5.3)))

B<-data.frame(cbind(c(‘R1′,’R2′,’R3′,’R4’),c(5,4.9,5.2,5.1)))

  • 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-05-25T03:41:24+00:00Added an answer on May 25, 2026 at 3:41 am

    General R advice: DON’T USE cbind WHEN IT’S NOT NECESSARY:

    A <- data.frame(X1=c('R1','R1','R2','R4','R4','R4'),X2=c(5.1,4.8,4.9,5.0,5.0,5.3))
    B <- data.frame(X1=c('R1','R2','R3','R4'),X2=c(5,4.9,5.2,5.1))
    

    (You made factors of those numbers. And you cannot apply arithmetic operators to factors.)

    When there are non-unique matches, the merge function returns all possible pairs:

    merge(A,B, by=1)
    merge(A,B, by=1)[,2] - merge(A,B, by=1)[,3]
    #[1]  0.1 -0.2  0.0 -0.1 -0.1  0.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for advice and elegant solution extracting properties and values into any convenient data
I am getting ready to learn PHP. I am looking for advice from other
I am looking for advice about how to parse a single list, using two
I was looking for advice on how to store data in a database for
I'm looking for advice on how to trigger this view function insertNewLine from a
I'm looking for advice/opinions on Javascript control libraries like ext-js, dhtmlx, jquery-UI etc... I've
Looking for advice on the best technique for saving complex Python data structures across
Looking for advice in removing duplication from this snippet: foreach (Car car in carList)
Looking for advice on passing variables from page to page without using QueryString. The
I'll looking for advice/resources to write a program that can intercept system calls from

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.