Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created February 23, 2017 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/372cace83de0da84fb0b836eaf909f6e to your computer and use it in GitHub Desktop.
Save Keiku/372cace83de0da84fb0b836eaf909f6e to your computer and use it in GitHub Desktop.
The example codes on dplyr package.
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