r,与< u+ 200b>

发布于 2025-02-05 07:48:18 字数 361 浏览 2 评论 0原文

我从Excel导入了一张桌子。

如果我从环境中打开此表(作为数据框),它看起来不错:

Name  Ser_NR 
ABC   123
DEF   458
EGS   954

但是,我指出,对于某些行,过滤器函数不起作用。 然后,我将此数据框放到控制台中, 它向我展示了这一点:

Name  Ser_NR 
ABC   123
DEF   458<U+200B>
EGS   954 <U+200B>

此列的类型“ ser_nr”是字符。 我想要“删除”&lt; u+200b&gt;或将类型更改为普通字符。

谁能帮我吗? 谢谢!

I imported a table from an excel.

If I open this table (as dataframe) from the environment it looks fine:

Name  Ser_NR 
ABC   123
DEF   458
EGS   954

However, I noted that for some rows, the filter function doesn't work.
Then I put this dataframe into Console,
It shows me this:

Name  Ser_NR 
ABC   123
DEF   458<U+200B>
EGS   954 <U+200B>

The type of this column "Ser_NR" is character.
I want "remove" <U+200B> or change the type to normal character.

Can anyone help me?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

灯角 2025-02-12 07:48:18

尝试

df$Ser_NR <- as.integer(df$Ser_NR)
df

Try

df$Ser_NR <- as.integer(df$Ser_NR)
df
花心好男孩 2025-02-12 07:48:18

这是对以下方面的解决方案:

library(dplyr)

df <- tibble::tribble(
         ~Name,       ~Ser_NR,
         "ABC",         "123",
         "DEF", "458<U+200B>",
         "EGS", "954<U+200B>"
         )

df %>% 
  mutate(Ser_NR = gsub("<([[:alpha:]][[:alnum:]]*)(.[^>]*)>([.^<]*)", "\\3", Ser_NR))

为我们提供:

# A tibble: 3 x 2
  Name  Ser_NR
  <chr> <chr> 
1 ABC   123   
2 DEF   458   
3 EGS   954

Here's a solution with regex:

library(dplyr)

df <- tibble::tribble(
         ~Name,       ~Ser_NR,
         "ABC",         "123",
         "DEF", "458<U+200B>",
         "EGS", "954<U+200B>"
         )

df %>% 
  mutate(Ser_NR = gsub("<([[:alpha:]][[:alnum:]]*)(.[^>]*)>([.^<]*)", "\\3", Ser_NR))

Which gives us:

# A tibble: 3 x 2
  Name  Ser_NR
  <chr> <chr> 
1 ABC   123   
2 DEF   458   
3 EGS   954
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文