How to use unite() function In R Language
This function is available in tidyr package and we have to load that package and will combine columns.
Syntax:
unite(dataframe, combined_columnname, c(columns))
where,
- dataframe is the input dataframe
- columns are the dataframe columns to be combines
- combined_columnname is the name of the combined column
Example:
R
# import tidyr package library (tidyr) # create dataframe data = data.frame (firstname= c ( "akash" , "kyathi" , "preethi" ), lastname= c ( "deep" , "lakshmi" , "savithri" ), marks= c (89, 96, 89)) # display print (data) # combine first name and last name columns # with blank separator data = unite (data, fullname, c (firstname, lastname)) # display data |
Output:
How to Combine Two Columns into One in R dataframe?
In this article, we will discuss how to combine two columns into one in dataframe in R Programming Language.