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

  • Hands-On Data Science with R
  • Vitor Bianchi Lanzetta Nataraj Dasgupta Ricardo Anjoleto Farias
  • 116字
  • 2021-06-10 19:12:37

Using arrange for sorting

Using arrange method is used to sort datasets as shown as follows:

# Sort the dataset in descending order of Income (high to low) 
arrange(tstate, desc(Income)) 
 
# Sort by Region and Illiteracy (within Region) 
arrange(tstate, Region, desc(Income)) 
 
## Mutate 
# The verb mutate is used to add new columns to a dataset, most commonly to represent a calculated value 
 
# For instance to find population on a per square mile basis: 
mutate(tstate, pop_per_sq_mile = Population/Area) 

If you want to keep only the newly created variable, use transmute, as shown:

transmute(tstate, pop_per_sq_mile = Population/Area) 
# # A tibble: 50 x 1 
# pop_per_sq_mile 
# <dbl> 
#   1    0.0712905261 
# 2    0.0006443845 
# 3    0.0195032491 
 
主站蜘蛛池模板: 安化县| 岳西县| 潜江市| 宝鸡市| 开阳县| 舞钢市| 阿勒泰市| 开封县| 黔南| 栾城县| 固镇县| 师宗县| 饶河县| 休宁县| 金昌市| 县级市| 广丰县| 宜兰市| 南靖县| 平乐县| 泰兴市| 日照市| 克拉玛依市| 宾阳县| 如东县| 耿马| 且末县| 陈巴尔虎旗| 柞水县| 广安市| 肥东县| 嘉善县| 五台县| 新巴尔虎左旗| 义马市| 安宁市| 宜兴市| 池州市| 修文县| 荆门市| 昌黎县|