如何以char格式,空白,r中的curreny等混合变量清洁列

发布于 2025-01-25 06:22:17 字数 319 浏览 4 评论 0原文

我有一个初创公司的数据集,其中我有一个称为“金额”的列,只不过是每个创业公司的估值。当我尝试绘制绘图时,绘图丑陋,我发现它们是“ char”格式的值彼此混合。您可以在此处看到示例图片:

“ “

我是R的初学者,我尝试了几个小型代码,但没有奏效。我想删除“字符串行”,“空白行”和“无数字的空$符号行”,然后将其余行转换为数字。

I have a dataset of startups, in which I have a column called "Amount" which is nothing but the valuations of each startup. when I tried to plot, the plot came out ugly and I found that those were in "char" format but when I tried to see the values in a column using table(copy$Amount) it showed all values mixed to each other. u can see the example pics here:

1
2

I'm a beginner to R, I tried several small codes but nothing worked. I want to remove the "string rows", "blank row", and "empty $ symbol row without number" and convert the remaining rows into numbers.

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

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

发布评论

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

评论(1

雪若未夕 2025-02-01 06:22:17

您可以从Readr软件包中使用parse_number,其中:

...在第一个数字之前或之后删除所有非数字字符。位置指定的分组标记在数字内被忽略。

例如:

> x <- c("1,000", "$1,000", "$1,000", "1,000$")
> readr::parse_number(x)
[1] 1000 1000 1000 1000

You can use parse_number from the readr package, which:

...drops any non-numeric characters before or after the first number. The grouping mark specified by the locale is ignored inside the number.

For example:

> x <- c("1,000", "$1,000", "$1,000", "1,000
quot;)
> readr::parse_number(x)
[1] 1000 1000 1000 1000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文