- Hands-On Exploratory Data Analysis with R
- Radhika Datar Harish Garg
- 180字
- 2021-06-24 14:10:44
The unite() function
unite focuses on combining multiple columns into a single column. This is regarded as a convenience function that pastes multiple columns together.
The basic implementation syntax is as follows:
unite(data, col, ..., sep = "_", remove = TRUE)
Here, the parameters are as follows:
- data: Data frame.
- col: The name of the column to be added. Further specification of columns can be added.
- sep: Separator to use between the values.
- remove: If TRUE, this will remove input columns from the data frame mentioned.
In our dataset, where we need to combine Fuel Type columns and Drive versus Cylinder attributes to understand the fuel efficiency, we can use the unite function with a separator value to combine the columns:
> mpg4<- unite_(mpg, "FuelEfficiency", c("drv","fl")) > View(mpg4)
The output generated is as follows:

mpg4 is a new dataset created as follows:

FuelEfficiency is the column that combines both attributes with a separator, _.
We can combine multiple columns together as one in a similar fashion, with the main focus being to tidy up the data.
推薦閱讀
- Hands-On Linux for Architects
- 數據挖掘方法及天體光譜挖掘技術
- Implementing Oracle API Platform Cloud Service
- 空間站多臂機器人運動控制研究
- Linux Shell編程從初學到精通
- Ansible 2 Cloud Automation Cookbook
- Learning Linux Shell Scripting
- ADuC系列ARM器件應用技術
- 電氣控制及Micro800 PLC程序設計
- 智能座艙之車載機器人交互設計與開發
- R:Predictive Analysis
- 深度剖析:硬盤固件級數據恢復
- 仿蛇機器人的設計與制作
- Mastering Adobe Premiere Pro CS6 Hotshot
- CAD/CAE/CAM技術