我想搜索其中包含"3“的任何内容,并将其替换为"3D”。我尝试了gsub和stringr,但似乎不能正确地使用正则表达式。任何帮助都是最好的!我在这上面花的时间太长了。
type_3d <- as.matrix(c("3D","3D","3D Column","3D Plot","3D Scatter","3D Plot","3D Scatter","3d Column"))发布于 2011-10-15 02:01:04
Andrie对你的问题有一个很好的答案。
虽然您正在寻找的东西可以解决特定的问题,但在R中查找数据中所有这些乱七八糟的东西的一般问题是相当单调乏味的,尽管有专门为此设计的工具。你可能想看看Google Refine。
发布于 2011-10-15 01:33:04
我不确定我是否正确理解了您的意思,因为您描述的是gsub的一个非常简单的用法
gsub("3", "3D", type_3d)
[,1]
[1,] "3DD"
[2,] "3DD"
[3,] "3DD Column"
[4,] "3DD Plot"
[5,] "3DD Scatter"
[6,] "3DD Plot"
[7,] "3DD Scatter"
[8,] "3Dd Column" 或者你的意思是:
> gsub(".*3.*", "3D", c(type_3d, "Some other text without a three"))
[1] "3D" "3D"
[3] "3D" "3D"
[5] "3D" "3D"
[7] "3D" "3D"
[9] "Some other text without a three"https://stackoverflow.com/questions/7771331
复制相似问题