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

  • 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 
 
主站蜘蛛池模板: 富平县| 成武县| 建瓯市| 成武县| 剑川县| 屏东县| 濉溪县| 咸丰县| 尼勒克县| 青州市| 利川市| 古田县| 竹山县| 浦江县| 浦城县| 获嘉县| 全州县| 古丈县| 呈贡县| 娄底市| 朝阳市| 山东省| 永春县| 黑山县| 通州区| 陆良县| 永嘉县| 赞皇县| 黄陵县| 宜春市| 阿荣旗| 华坪县| 巢湖市| 兴宁市| 岢岚县| 靖西县| 武汉市| 延长县| 大丰市| 寿宁县| 雅江县|