in Education by
I have 2 types (say a and b) of dataframes in my R environment, each with 20 years. I am trying to write a loop in R such that I can merge the 1st dataframe in type a with 1st dataframe in type b by a particular variable. I have a1,a2,...,a20 and b1,b2,...,b20 in my environment and the common variable by which I am trying to merge is ID. I have tried with the code below, but I am guessing the issue is inside the merge function where I am defining the x and y. for (i in 1:20) { assign(paste0("ab", i), merge(x="a"&i, y="b"&i, by.x = 'ID', by.y='ID', all.x=TRUE)) } I want to have 20 new dataframes (called ab1, ab2,..., ab20) with the information from type a and b together. Any help will be greatly appreciated and please do point it to me in case there exists a same question. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
How about this: for (i in 1:20) { assign(paste0("ab", i), merge(x=get(paste0("a",i)), y=get(paste0("b",i)), by.x = 'ID', by.y='ID', all.x=TRUE))

Related questions

0 votes
    I have 2 types (say a and b) of dataframes in my R environment, each with 20 years. I am trying ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Dataframes can be converted into a matrix by calling the following function data ______ (a) matr() (b) matrix ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    In order to use the R-related functionality in Dundas BI, you must have access to an existing _________ (a ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I want to exclude specific participants from a DataFrame and create it from an existing DataFrame. I want a method ... worked for me. Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Columns can be arranged in descending order too by using the special ____ operator. (a) asc() (b) desc( ... Operations of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which of the following sort a dataframe by the order of the elements in B? (a) x[rev(order(x$B)), ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    In 1991, R was created by Ross Ihaka and Robert Gentleman in the Department of Statistics at the University of ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    We can dump() R objects to a file by passing _____ (a) character vector of their names (b) object name ... Operations of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    If a command is not complete at the end of a line, R will give a different prompt, by default it is ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    One way to pass data around is by de parsing the R object with _________ (a) dput() (b) write() (c ... and Operations of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    The primary source code copyright for R is held by the ___________ (a) R Foundation (b) S Foundation (c) ... Started of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have a data which consists of two columns "Students" & "points" x...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    How can I sort a data.frame by multiple columns. E.x. I would like to sort the column q(descending) by column f (ascending) dd...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Order Bars in ggplot2 bar graph (14 answers) Closed 3 years ago. I ... -interventions", "Compliance", "Timing of outcome assessments" data...
asked Jun 1, 2022 in Education by JackTerrance
...