> X864291X8X74
[1] 8.0000000000 9.0000000000 10.0000000000 6.0000000000 8.0000000000
10 Levels: 0.0000000000 10.0000000000 12.0000000000 3.0000000000 4.0000000000 6.0000000000 ... NULL
> as.numeric(X864291X8X74)
[1] 8 9 2 6 8
我误解了什么?不应该是 as.numeric 8 9 10 6 8 的结果吗?
我怎样才能得到正确的结果?
你的向量是factor
。这个问题已经被问过很多次了,例如:here https://stackoverflow.com/questions/7611810/converting-a-factor-to-numeric-without-losing-information-r-as-numeric-doesn, here https://stackoverflow.com/questions/4798343/convert-factor-to-integer, here https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-an-integer-numeric-without-a-loss-of-information。为了将因子转换为数字,您必须转换为character
第一的。尝试:
as.numeric(as.character(my_vec))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)