Convert from list to numeric

99封情书 提交于 2019-12-04 11:42:42

问题


Hi I've had a look at a lot of other qns/answers and haven't been able to resolve coercing from list form to numeric form. If it is of use, the list is originally drawn from a factor (and is 1x33 rows).

My list is defined by:

tmpseqsf[[1]]

which provides:

       TradeValue
1    72914431
2       25325
3       20139
4       ...

So based on other advice (Stackoverflow, etc) I use:

tmpx <-as.numeric(tmpseqsf[[1]])

but I get the error:

Error: (list) object cannot be coerced to type 'double'

And just confirming nothing has happened:

is.numeric(tmpseqsf[[1]])
[1] FALSE

Is there something I am completely missing?


回答1:


If the values are of type factor, then you should convert them by as.numeric(as.character(unlist(tmpseqsf[[1]])))



来源:https://stackoverflow.com/questions/43599347/convert-from-list-to-numeric

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!