Question:

How will you merge two dataframes in R programming language?

Answer:

Merge () function is used to combine two dataframes and it identifies common rows or columns between the 2 dataframes. Merge () function basically finds the intersection between two different sets of data.

Merge () function in R language takes a long list of arguments as follows –

Syntax for using Merge function in R language -

 merge (x, y, by.x, by.y, all.x  or all.y or all )

  • X represents the first dataframe.
  • Y represents the second dataframe.
  • by.X- Variable name in dataframe X that is common in Y.
  • by.Y- Variable name in dataframe Y that is common in X.
  • all.x - It is a logical value that specifies the type of merge. all.X should be set to true, if we want all the observations from dataframe X . This results in Left Join.
  • all.y - It is a logical value that specifies the type of merge. all.y should be set to true , if we want all the observations from dataframe Y . This results in Right Join.
  • all – The default value for this is set to FALSE which means that only matching rows are returned resulting in Inner join. This should be set to true if you want all the observations from dataframe X and Y resulting in Outer join.

Keywords:

© 2017 QuizBucket.org