【发布时间】:2019-07-14 08:30:36
【问题描述】:
我需要替换字符向量的某些值:
x <- data.frame(Strings = c("one", "two","three","four","five","four","five","four","five","two","thre","two","three","two","three"), stringsAsFactors = FALSE)
> x
Strings
1 one
2 two
3 three
4 four
5 five
6 four
7 five
8 four
9 five
10 two
11 three
12 two
13 three
14 two
15 three
在 python 中,我会这样做:
x["Strings"].replace(["one", "two", "thre","three"], ["One","Two","Three","Three"], inplace=True)
但在 r 中,函数 replace() 不能以同样的简单方式工作。 Stackoverflow 中有很多字符串替换的解决方案,但没有一个能这么简单。这在 r 中可能吗?
【问题讨论】:
标签: r string data-manipulation