如何更改特定列的值格式-R
假设我有一个数据集流量
column coper_count
显示每个流量计数站的流量计数:
triffate_counting_counting_station_id | agript_count_count |
---|---|
1 | 24.592 |
2 | 65.500 |
3 | 4.976 |
问题是<代码是<代码 traffil_count
被解释为浮点类型,而值应表示整数数字。 As an example, when I generate a new column Traffic_count_TimesTen
which is formulated as traffic$Traffic_count*10
, the resulting table is:
Traffic_counting_station_ID | Traffic_count | Traffic_count_TimesTen |
---|---|---|
1 | 24.592 | 245.92 |
2 | 65.500 | 655.00 |
3 | 4.976 | 49.76 |
当我应用流量$ clumag_count&lt; - as.integer(流量$ triffum_count)
code> traffum_count
的值分别为25、66和5。
应用流量$ crivical_count&lt; - as.numeric(gsub(“。”,“”,traffic $ crivate_count))
删除定义类型float的点,导致 na 。
我如何将流量_Count的值转换为整数数字,从而将 clockugh_count
中的值视为24592、65500、4976,而 code> cropaile> cropail_count_timesten
中的值则被视为245920,655000和49760?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
gsub
解决方案几乎是正确的。尝试以下内容:说明
。
是REGEX中的一个特殊标志,意思是“任何”字符,因此它将用替换每个字母“”
。如果您想更换点,则需要在其前面放置\
。但是,当R试图解释字符串中的单个“”时,我们需要告诉R本身,不要用另一个斜杠进行预处理。因此\\
your
gsub
solution is almost correct.Try the following:Explanation
.
is a special sign in regex, meaning "any" character, therefore it will replace every letter with""
. If you exlicitly want to replace a dot, you need to put a\
in front of it. But as R tries to interpret a single "" within a string we need to tell R itself not to preprocess the slash with another slash. therefore\\