我想将因子数据转换为数字向量,而我使用
as.numeric.factor(data$a)
但它返回带有警告消息的NA:
In as.numeric.factor(data$mande) : NAs introduced by coercion
data$mande
如下:
[1] 487,133,554 935,324,956 911,218,601 852,769,205 827,303,376 822,798,080
[7] 790,742,637 705,988,860 708,069,041 822,576,228 1,030,917,702 993,681,929
[13] 612,788,943 476,228,323 698,824,239 742,635,939 1,015,681,208 560,344,408
[19] 534,239,403 593,466,633 845,546,563 945,040,231 662,027,082 939,183,094
[25] 567,896,868 895,193,731 596,684,741 816,154,728 584,770,698 888,124,557
[31] 714,095,214 926,332,917 1,048,748,054 859,163,643 779,785,761 769,739,089
[37] 637,955,119 1,013,591,480 847,255,948 401,628,954 753,706,919 610,029,520
[43] 643,316,067 864,681,638 1,030,589,838 772,686,642 915,548,834 839,074,449
[49] 944,666,653 577,565,091 507,186,304 493,750,994 533,159,975 777,006,295
[55] 740,415,930 937,675,395 957,068,513 811,641,347 911,885,721 937,100,021
[61] 931,185,060 576,935,553
62 Levels: 1,013,591,480 1,015,681,208 1,030,589,838 1,030,917,702 1,048,748,054 ... 993,681,929
我该怎么做才能拥有数字矢量数据?
答案 0 :(得分:2)
问题是由数据格式引起的。使用此:
as.numeric(gsub(",","",as.character(data$mande)))
gsub
删除逗号并启用R将数据转换为数字。
答案 1 :(得分:0)
尝试
as.numeric(as.character(data$mande))