I have a data frame in r that includes a numeric column. I want to create a new column, which should contain a new value A if original is < 100 and a new value B if original is > 100.
Like this?
library(dplyr)
set.seed(100)
my_set = data.frame(x = rnorm(5, mean = 100))
#> x
#> 1 99.49781
#> 2 100.13153
#> 3 99.92108
#> 4 100.88678
#> 5 100.11697
my_set %>% mutate(y = ifelse(x > 100, "A","B"))
#> x y
#> 1 100.31863 A
#> 2 99.41821 B
#> 3 100.71453 A
#> 4 99.17474 B
#> 5 99.64014 B
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.