Created
February 23, 2017 02:12
-
-
Save Keiku/372cace83de0da84fb0b836eaf909f6e to your computer and use it in GitHub Desktop.
The example codes on dplyr package.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
iris_df <- as_data_frame(iris) | |
iris_df %>% rename_(.dots = setNames(names(.), toupper(names(.)))) %>% head(2) | |
# A tibble: 2 × 5 | |
# SEPAL.LENGTH SEPAL.WIDTH PETAL.LENGTH PETAL.WIDTH SPECIES | |
# <dbl> <dbl> <dbl> <dbl> <fctr> | |
# 1 5.1 3.5 1.4 0.2 setosa | |
# 2 4.9 3.0 1.4 0.2 setosa | |
x <- c("A", "B", "C", "A", "B") | |
recode(x, .dots = setNames(c(1, 2, 3), c("A", "B", "C"))) | |
# [1] 1 2 3 1 2 | |
x <- c(1, 2, 3, 2, 1) | |
recode(x, .dots = setNames(c("A", "B", "C"), c(1, 2, 3))) | |
# [1] "A" "B" "C" "B" "A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment