Merging two Data Frames
In R, we can merge two data frames using the merge() function provided both the data frames should have the same column names. We may merge the two data frames based on a key value.
Syntax: merge(dfA, dfB, …)
Example:
R
# Merging two data frames in R d1 <- data.frame (name= c ( "shaoni" , "soumi" , "arjun" ), ID= c ( "111" , "112" , "113" )) d2 <- data.frame (name= c ( "sounak" , "esha" ), ID= c ( "114" , "115" )) total <- merge (d1, d2, all= TRUE ) print (total) |
Output:
name ID
1 arjun 113
2 shaoni 111
3 soumi 112
4 esha 115
5 sounak 114
Data Reshaping in R Programming
Generally, in R Programming Language, data processing is done by taking data as input from a data frame where the data is organized into rows and columns. Data frames are mostly used since extracting data is much simpler and hence easier. But sometimes we need to reshape the format of the data frame from the one we receive. Hence, in R, we can split, merge and reshape the data frame using various functions.
The various forms of reshaping data in a data frame are:
- Transpose of a Matrix
- Joining Rows and Columns
- Merging of Data Frames
- Melting and Casting
Contact Us