
上QQ阅读APP看书,第一时间看更新
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