官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 同心县| 特克斯县| 清苑县| 昔阳县| 澳门| 定兴县| 水富县| 高州市| 芒康县| 平罗县| 玛曲县| 紫云| 唐山市| 扎鲁特旗| 集贤县| 铁力市| 浦江县| 东城区| 清流县| 宜丰县| 上虞市| 呼伦贝尔市| 临海市| 五峰| 江陵县| 阿拉善左旗| 蓬溪县| 漳平市| 呈贡县| 措美县| 定陶县| 富源县| 浙江省| 嵩明县| 长阳| 玉环县| 常德市| 安图县| 遂溪县| 陇川县| 涞源县|