如何回顾一个字符串值,该值的字符串值在内部?
我在尝试重新解码变量时使用了DPLYR软件包和函数进行了回顾,因为原始作者有许多错别字。例如,我已经设法执行“ RKS(umik)” =“ rks”或“ Cu” =“ Cub”,但是代码中的其他示例不会更改。在某些情况下,我什至复制了原始错别字(即“egy。Eu”),但它不起作用。
这些值应该是ISO3国家代码,仅供参考。
在这种情况下,我还注意到的是,某种程度上看起来像“(“ Che””与“ nor”中的“)”。有人知道一种更好的方法吗?先感谢您!
data<-data%>%
mutate(parties=recode(parties,
" RKS (UNMIK)"="RKS",
"(CHE"="CHE",
"EGY. EU"="EGY,EU",
"BRA. PRY"="BRA-PRY",
"CU"="CUB",
"NOR)"="NOR",
"VNM)KOR"="VNM,KOR"))
I am using dplyr package and the function recode while trying to recode a variable, because original authors have many typos. I have managed for instance to do "RKS (UNMIK)"="RKS" or "CU"="CUB" but the other examples from the code don't change. In some cases I even copy-pasted the original typo (i.e. "EGY. EU"), but it didn't work.
These values should be iso3 country codes, fyi.
What I also noticed in this case is that somehow looks like the "(" in "CHE" is matched by the ")" in "NOR". Does anyone know a better way to do it? Thank you in advance!
data<-data%>%
mutate(parties=recode(parties,
" RKS (UNMIK)"="RKS",
"(CHE"="CHE",
"EGY. EU"="EGY,EU",
"BRA. PRY"="BRA-PRY",
"CU"="CUB",
"NOR)"="NOR",
"VNM)KOR"="VNM,KOR"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个示例数据集(DF),并根据您在问题中列出的内容标记了列。之后,我使用了DPLYR的Rename()命令来创建一个名为“ new_data”的新对象。
“ =”左侧的值表示新名称,右侧的值表示当前名称。
希望这很有帮助!
I created a sample dataset (df) and labeled the columns according to what you listed in your question. After that I used the rename() command from dplyr to create a new object called "new_data".
The values on the left of the '=' represent the new names, and the values on the right represent the current names.
Hope this is helpful!