如何回顾一个字符串值,该值的字符串值在内部?

发布于 2025-02-11 15:33:04 字数 593 浏览 0 评论 0原文

我在尝试重新解码变量时使用了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2025-02-18 15:33:04

我创建了一个示例数据集(DF),并根据您在问题中列出的内容标记了列。之后,我使用了DPLYR的Rename()命令来创建一个名为“ new_data”的新对象。

“ =”左侧的值表示新名称,右侧的值表示当前名称。

new_data <- df %>% 
  rename("RKS"     = " RKS (UNMIK)",
         "CHE"     = "(CHE",
         "EGY, EU" = "EGY. EU",
         "BRA-PRY" = "BRA. PRY",
         "CUB"     = "CU",
         "NOR"     = "NOR)",
         "VNM,KOR" = "VNM)KOR")

希望这很有帮助!

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.

new_data <- df %>% 
  rename("RKS"     = " RKS (UNMIK)",
         "CHE"     = "(CHE",
         "EGY, EU" = "EGY. EU",
         "BRA-PRY" = "BRA. PRY",
         "CUB"     = "CU",
         "NOR"     = "NOR)",
         "VNM,KOR" = "VNM)KOR")

Hope this is helpful!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文