单词替换(使用 R 语言)
Word Replacement (using The R Language)
我正在尝试用 R 语言替换一个词
我使用 If 函数来替换 R 中的单词。它工作正常。但是,如果 workd 以小写字母开头或 Word 是大写字母,则它不会替换。例如:如果我想替换 Apple,我使用 if 代码将其替换为 Apples。如果该列包含 APPLE 或 AppleLE,则不会替换。谁能帮忙用哪个函数替换一个作品不分大小写
我在 R 脚本中使用 If 函数
解决该问题的一种可能方法是将您的列更改为全低或全高。
library(stringr)
library(dplyr)
df = data.frame(
col_0 = c(1,2,3),
col_1 = c("aPPLE","apple","grape"))
df %>%
mutate(col_1 = tolower(col_1)) %>%
mutate(col_1 = str_replace(col_1, "apple", "orange"))
我正在尝试用 R 语言替换一个词
我使用 If 函数来替换 R 中的单词。它工作正常。但是,如果 workd 以小写字母开头或 Word 是大写字母,则它不会替换。例如:如果我想替换 Apple,我使用 if 代码将其替换为 Apples。如果该列包含 APPLE 或 AppleLE,则不会替换。谁能帮忙用哪个函数替换一个作品不分大小写
我在 R 脚本中使用 If 函数
解决该问题的一种可能方法是将您的列更改为全低或全高。
library(stringr)
library(dplyr)
df = data.frame(
col_0 = c(1,2,3),
col_1 = c("aPPLE","apple","grape"))
df %>%
mutate(col_1 = tolower(col_1)) %>%
mutate(col_1 = str_replace(col_1, "apple", "orange"))