如何从因子更改为数值而不会出现错误

时间:2019-06-27 19:51:40

标签: r

我正在尝试将数据帧中列的类从factor更改为numeric,但是值会更改:

Plot     DWT
1         1.29
2         0.82
3         1.21
4         3.16


Site.copy$DWT<-as.numeric(as.character(Site.copy$DWT))

#or

Site.copy$DWT<-as.numeric(levels(Site.copy$DWT))[as.integer(Site.copy$DWT)]

#Both codes result in this:

Plot     DWT
1        1.290000e+00
2        8.200000e+01
3        1.210000e+00
4        3.160000e+00

我该如何解决?

1 个答案:

答案 0 :(得分:2)

您必须更改R中的选项。 options(scipen = 999)

它应该起作用,这会阻止科学计数法。