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

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 
 
主站蜘蛛池模板: 贵定县| 多伦县| 夹江县| 炉霍县| 灵寿县| 海伦市| 曲水县| 友谊县| 若尔盖县| 深泽县| 周至县| 雷山县| 潼南县| 平塘县| 恩施市| 安丘市| 伊川县| 巴彦县| 南江县| 弋阳县| 江源县| 昂仁县| 黑龙江省| 崇仁县| 安国市| 淳化县| 托克托县| 宜君县| 丰宁| 南江县| 广灵县| 永春县| 华池县| 靖宇县| 绩溪县| 江北区| 格尔木市| 丰宁| 佛教| 东阳市| 苍溪县|