Next we continue to understand some of the common functions in Dplyr.
1, ranking
Each of the following functions can be used to sort the data differently
Row_number (x)
Ntile (x, N)
Min_rank (x)
Dense_rank (x)
Percent_rank (x)
Cume_dist (x)
See some examples in detail.
X <-C (5, 1, 3, 2, 2, NA) x
Row_number (x)
Row_number is the size of the data to sort, encountered duplicate values, sorting continues to add 1, missing values do not count in
Min_rank (x)
Min_rank is to sort the data size, encounter duplicate values, and sort the same, but each value occupies one position and the missing value does not count toward
Dense_rank (x)
Dense_rank is to sort the data size, encounter duplicate values, sort the same, all duplicate values only one position, missing values do not count toward
Percent_rank (x)
Percent_rank is a percent sort of data, each representing a percentage position in the overall position of the data
Cume_dist (x)
Cume_dist is a numeric value that centers all the points in the 0-1, each of which represents the location of the data, a bit like percent_rank.
Ntile (x, 2)
Ntile can specify the number of data to sort, and then loop the sort data to sort the data.
2, Recode ()
Recode (. x, ...,. default = null,. Missing = null)
Data substitution functions, which are very flexible to use in data substitution.
x <-sample (C ("A", "B", "C"), and replace = TRUE) x
Recode (x, a = "Wo")
Recode (x, a = "Wo",. Default = Na_character_)
X<-sample (1:5,10,rep=t) x
Recode (x, ' 2 ' = 20L, ' 4 ' = 40L)
Recode (x, ' 2 ' = "B", ' 4 ' = "D")
Recode (x, "a", "B")
Recode (x, "a", "B",. Default = "Wo")
x <-C (1:4, NA) x
Recode_factor (x, ' 1 ' = "Z", ' 2 ' = "Y", ' 3 ' = "x")
Recode_factor (x, ' 1 ' = "Z", ' 2 ' = "Y",. Default = "D",. Missing = "M")
Recode_factor (Factor (Letters[1:3]), B = "Z", c = "Y")
Dplyr common functions for data manipulation (4)