本文介绍了在R中将十六进制转换为小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现在 fBasics
包中有一个名为 .hex.to.dec
的函数。
I found out that there is function called .hex.to.dec
in the fBasics
package.
当我执行 .hex.to.dec(a)
时,它可以正常工作。
When I do .hex.to.dec(a)
, it works.
我有一个数据框,其中有一列 samp_column
,其中包含这样的值:
I have a data frame with a column samp_column
consisting of such values:
a373, 115c6, a373, 115c6, 176b3
当我执行 .hex.to.dec(samp_column)
时,出现以下错误:
When I do .hex.to.dec(samp_column)
, I get this error:
.hex.to.dec(as.character(samp_column))
,我得到这个错误:
When I do .hex.to.dec(as.character(samp_column))
, I get this error:
这样做的最佳方式是什么?
What would be the best way of doing this?
推荐答案
使用 base :: strtoi
将十六进制字符向量转换为整数:
Use base::strtoi
to convert hexadecimal character vectors to integer:
strtoi(c("0xff", "077", "123"))
#[1] 255 63 123
这篇关于在R中将十六进制转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!