Turn columns into numeric, given list of columns

2226 views r

I have a list of columns, let's call them: ASSET, LIAB.

I want to turn both of them into columns. I'm using R data-table, which gives me warnings that tell me that it was converted back to character (that is, be completely useless) when I do it in a style similar to that which I would use in Python Pandas:

for (v in numeric_vars) {
    ris_df[, eval(v)] <- as.numeric(gsub(',', '', ris_df[, eval(v)]))

The list numeric_vars is the list of variables, currently string-like objects (e.g. 1,000), which I want turned into integers.

answered question

1 Answer


Don't you need to use with=FALSE to enable data.frame-like syntax to work on data.table objects?

ris_df[, eval(v), with = FALSE] <- as.numeric(gsub(',', '', ris_df[, eval(v), with = FALSE]))

posted this

Have an answer?


Please login first before posting an answer.