Created
July 5, 2017 02:40
-
-
Save MonkmanMH/cdaad0112afc25fac8e1622eeca96303 to your computer and use it in GitHub Desktop.
mutate alternate values
This file contains 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(tidyverse) | |
datatab <- as.tibble(c(1:10)) | |
# modulo division | |
datatab$value %% 2 | |
# since we have alternating even and odd value in "value" variable | |
datatab %>% | |
mutate(valueplus = ifelse((value %% 2) == 0, "even", "odd")) | |
# for row numbers (i.e. 'rownames') can't put in a pipe | |
mutate(valueplus2 = ifelse((as.numeric(rownames(datatab)) %% 2) == 0, "even", "odd")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment