Convert from list to numeric

Tim picture Tim · Apr 25, 2017 · Viewed 61.6k times · Source

I am tying to coerce 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?

Answer

ahly picture ahly · Aug 31, 2018

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