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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:56:07+00:00 2026-05-23T12:56:07+00:00

I have a input dataframe like this (the real one is very large, so

  • 0

I have a input dataframe like this (the real one is very large, so I want to do it faster):

df1 <- data.frame(A=c(1:5), B=c(5:9), C=c(9:13))

  A B  C
1 1 5  9
2 2 6 10
3 3 7 11
4 4 8 12
5 5 9 13

I have a dataframe with replacement code like this (the entries here maybe more than df1):

df2 <- data.frame(X=c(1:15), Y=c(101:115))

    X   Y
1   1 101
2   2 102
3   3 103
4   4 104
5   5 105
6   6 106
7   7 107
8   8 108
9   9 109
10 10 110
11 11 111
12 12 112
13 13 113
14 14 114
15 15 115

By matching df2$X with value in df1$A and df1$B, I want to get a new_df1 by replace df1$A and df1$B with the corresponding values in df2$Y, i.e. resulting this new_df1

  A    B    C
1 101  105  9
2 102  106 10
3 103  107 11
4 104  108 12
5 105  109 13

Could you mind to give me some guidance how to do it faster in R, as my dataframe is very large? Many 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-05-23T12:56:07+00:00Added an answer on May 23, 2026 at 12:56 pm

    It’s supereasy! You just need to get the proper offsets in the array.

    So for instance, to get the Y column of df2 corresponding to the values in the A column of df1 you’ll write df2$Y[df1$A]

    Hence, your code will be:

    df_new <- data.frame("A" = df2$Y[df1$A], "B" = df2$Y[df1$B], "C" = df1$C)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have input data that contain lines like this: -0.438185 -0.766791 0.695282 0.759100 0.034400
I have input checkbox something like this.. <input class=inputchbox id=Pchk type=checkbox name=check value=<%=Model.ID%> />
I have a function foo that takes a data frame as input and returns
I have input bytes from ffmpeg. I'd like to send this output to several
simple question: I have input fields with inside-labels! Just like the search-box on this
I have input, 34600 milliseconds I would like to output this in the format
I have input like this: [0|0|{A=145,B=2,C=12,D=18}|!][0|0|{A=167,B=2,C=67,D=17}|.1iit][196|0|{A=244,B=6,C=67,D=12}|10:48AM][204|0|{A=9,B=201,C=61,D=11}|Calculator][66|0|{A=145,B=450,C=49,D=14}|phone]0|0|{A=145,B=2,C=12,D=18}|!0|0|{A=167,B=2,C=67,D=17}|.1iit196|0|{A=244,B=6,C=67,D=12}|10:48AM204|0|{A=9,B=201,C=61,D=11}|Calculator66|0|{A=145,B=450,C=49,D=14}|phone; It appears as a continuous line, there are
If i have input text in form like this <form action=add.php method=post> <input type=text
I have input text that contains a ' like in this text Frank's Reel
I have a data frame that contains a number of fields. One of these

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.