- 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.
推薦閱讀
- 大數(shù)據導論:思維、技術與應用
- Splunk 7 Essentials(Third Edition)
- OpenStack for Architects
- 手把手教你學AutoCAD 2010
- Julia 1.0 Programming
- 現(xiàn)代機械運動控制技術
- Ceph:Designing and Implementing Scalable Storage Systems
- 網中之我:何明升網絡社會論稿
- 悟透AutoCAD 2009案例自學手冊
- Visual FoxPro程序設計
- 基于神經網絡的監(jiān)督和半監(jiān)督學習方法與遙感圖像智能解譯
- 嵌入式GUI開發(fā)設計
- HBase Essentials
- 玩機器人 學單片機
- 電氣自動化工程師自學寶典(基礎篇)