我有一个出版商列表,如下所示:
+--------------+
| Site Name |
+--------------+
| Radium One |
| Euronews |
| EUROSPORT |
| WIRED |
| RadiumOne |
| Eurosport FR |
| Wired US |
| Eurosport |
| EuroNews |
| Wired |
+--------------+我想创建以下结果:
+--------------+----------------+
| Site Name | Publisher Name |
+--------------+----------------+
| Radium One | RadiumOne |
| Euronews | Euronews |
| EUROSPORT | Eurosport |
| WIRED | Wired |
| RadiumOne | RadiumOne |
| Eurosport FR | Eurosport |
| Wired US | Wired |
| Eurosport | Eurosport |
| EuroNews | Euronews |
| Wired | Wired |
+--------------+----------------+我想了解如何复制我在Power Query中使用的代码:
搜索前4个字符
如果Text.Start(站点名称,4)= "WIRE“,则"Wired”否则
搜索最后3个字符
如果Text.End(站点名称,3)= "One“,则"RadiumOne”否则
如果没有找到匹配项,则添加"Rest“
它不必区分大小写。
发布于 2016-11-04 20:26:37
使用ifultools软件包和gsub中的properCase,我们将第一个单词后面的所有内容都替换为"“,即删除它,并分开处理Radium的例外情况。如果你有许多像Radium案例这样的例外,请更新你的帖子,这样我们就可以找到更好的解决方案:)
library("ifultools")
siteName=c("Radium One","Euronews","EUROSPORT","WIRED","RadiumOne","Eurosport FR","Wired US","Eurosport","EuroNews","Wired")
publisherName = gsub("^Radium$","Radiumone",gsub("\\s+.*","",properCase(siteName)))
# [1] "Radiumone" "Euronews" "Eurosport" "Wired" "Radiumone" "Eurosport" "Wired"
# [8] "Eurosport" "Euronews" "Wired"https://stackoverflow.com/questions/40421207
复制相似问题