How to use plyr package In R Language

The “plyr” package in R is used to work with data, including its enhancements and manipulations. It can be loaded and installed into the working space by the following command:

install.packages("plyr")

rbind.fill() method in R is an enhancement of the rbind() method in base R, is used to combine dataframes with different columns. The column names are numbers may be different in the input dataframes. Missing columns of the corresponding dataframes are filled with NA. The output dataframe contains a column only if it is present in any of the dataframes.

rbind.fill( df1, df2)

The following properties are maintained by the rbind.fill() method :

  • The dataframes are appended in the order of their specification in the function.
  • The total number of columns is equivalent to the summation of the number of columns of both the dataframes.
  • The total number of rows is equivalent to the summation of the number of rows of both the dataframes.
  • The appearance of columns is in the order of dataframe arguments declaration during the function call.
  • Empty cells are created in the missing columns.

Example: Adding Dataframe using plyr package

R




# loading the required library
library("plyr")
  
# declaring first dataframe
data_frame1 <- data.frame(col1 = c(2, 4, 6),
                          col2 = c(4, 6, 8),
                          col3 = c(8, 10, 12),
                          col4 = LETTERS[1 : 3])
  
print ("First Dataframe")
print (data_frame1)
  
# declaring second dataframe
data_frame2 <- data.frame(col4 = letters[1:4],
                          col5 = TRUE)
  
print ("Second Dataframe")
print (data_frame2)
print ("Combining Dataframe")
  
# binding dataframes
rbind.fill(data_frame1, data_frame2)


Output:

How to add dataframe to dataframe in R ?

In this article, we will see how to add dataframe at the end of another dataframe in R Programming Language.

Similar Reads

Method 1: Using rbind() method

The rbind() method in R works only if both the input dataframe contains the same columns with similar lengths and names. The dataframes may have a different number of rows. The class of the dataframe columns should be consistent with each other, otherwise, errors are thrown. The following properties are maintained :...

Method 2: Using plyr package

...

Method 3: Using dplyr package

The “plyr” package in R is used to work with data, including its enhancements and manipulations. It can be loaded and installed into the working space by the following command:...