使用tidyverse遇到的一个问题

1
2
3
4
5
6
7
library(tidyverse)

iris %>%
dplyr::mutate(temp = case_when(
Species == "setosa" ~ "lp",
TRUE ~ Species
))

报错:

1
2
3
4
5
6
Error in `dplyr::mutate()`:
! Problem while computing `temp = case_when(Species
== "setosa" ~ "lp", TRUE ~ Species)`.
Caused by error in `case_when()`:

Run `rlang::last_error()` to see where the error occurred.

这样就不报错:

1
2
3
4
5
6
iris %>% 
dplyr::mutate(Species = as.character(Species)) %>%
dplyr::mutate(temp = case_when(
Species == "setosa" ~ "lp",
TRUE ~ Species
))

使用tidyverse遇到的一个问题
https://lixiang117423.github.io/article/abug4tidyverse/
作者
小蓝哥
发布于
2022年11月23日
许可协议