i have about 30 columns within a dataframe of over 100 columns. the file i am reading in stores its numbers as characters. In other words 1300 is 1,300 and R thinks it is a character.
I am trying to fix that issue by replacing the ","
with nothing and turn the field into an integer. I do not want to use gsub
on each column that has the issue. I would rather store the columns as a vector that have the issue and do one function or loop
with all the columns.
I have tried using lapply
, but am not sure what to put as the "x
" variable.
Here is my function with the error below it
ItemStats_2014[intColList] <- lapply(ItemStats_2014[intColList],
as.integer(gsub(",", "", ItemStats_2014[intColList])) )
Error in
[.data.table
(ItemStats_2014, intColList) : When i is a data.table (or character vector), the columns to join by must be specified either using 'on=' argument (see ?data.table) or by keying x (i.e. sorted, and, marked as sorted, see ?setkey). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.