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

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 
 
主站蜘蛛池模板: 商城县| 砀山县| 绥江县| 德保县| 广西| 鄂尔多斯市| 新闻| 孙吴县| 蓬溪县| 墨玉县| 武邑县| 宁波市| 贵州省| 黄梅县| 天柱县| 措美县| 美姑县| 阳信县| 逊克县| 绵阳市| 利津县| 清水河县| 介休市| 内江市| 乐清市| 礼泉县| 沙洋县| 开原市| 新邵县| 鄱阳县| 金塔县| 嵊泗县| 云林县| 松原市| 紫金县| 石城县| 神木县| 多伦县| 大冶市| 富川| 琼中|