Comparison

Comparison: sort, order and arrange

vector (or factor)

(x <- swiss$Education[1:20])

[1] 12 9 5 7 15 7 7 8 7 13 6 12 7 12 5 2 8 28 20 9

sort the vector

sort(x)

[1] 2 5 5 6 7 7 7 7 7 8 8 9 9 12 12 12 13 15 20 28

partial sorting

sort(x, partial = c(10, 15))

[1] 2 5 5 7 7 7 7 6 7 8 8 9 9 12 12 12 13 28 20 15

Partial sorting in R is different with that in Wikipedia.

Comparison: transform, within and mutate

Here is another comparison between two basic functions transform and within, and a tidyverse function dplyr::mutate. They all can be used for data munipulation, adding a new column to a data.frame. head(mtcars)

mpg cyl disp hp drat wt qsec vs am gear carb

Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4

Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.

Comparison: subset and filter

A detailed introduction on subsetting is seen in Hadley Wickham’s Advanced R.

The three subsetting operators. The six types of subsetting. Important differences in behaviour for different objects (e.g., vectors, lists, factors, matrices, and data frames).

Benjamin on Stack Overflow answered the question 1 of the comparison between subset() and dplyr::filter().

They are, indeed, producing the same result, and they are very similar in concept.