在给定的数据集中,i在位置7处有cash
、other
和cash.other
.
df <- data.frame(values = c("loan", "cash", "equity",
"other", "commercial.news", "money.news", "cash.other"))
我试图返回grepl("cash.other", tolower(values)) ~ "Cash_Other"
,但它返回为Cash
.
在原来的rabrame中,我也有cash
,other
和cash.other
,这就是为什么我需要a返回cash.other
作为Cash_Other
.
df <- df %>%
mutate(values = case_when(
grepl("loan", tolower(values)) ~ "Lond",
grepl("cash", tolower(values)) ~ "Cash",
grepl("equity", tolower(values)) ~ "Equity",
grepl("other", tolower(values)) ~ "Other",
grepl("commercial.news", tolower(values)) ~ "Commercial_News",
grepl("money.news", tolower(values)) ~ "Money_News",
grepl("cash.other", tolower(values)) ~ "Cash_Other",
TRUE ~ as.character(values)
))
df
cash.other
的情况下,我如何返回Cash_Other
?
values
1 Lond
2 Cash
3 Equity
4 Other
5 Commercial_News
6 Money_News
7 Cash