0

First I uploaded a csv using "fread", then I was trying to convert a string vector into a float/numeric vector.

column1 looks like this:

print(column)
c("0.100005", "0.785222", "0.975222", ...)

I used something like this:

as.numeric(df$column1) 

or

as.double(df$column1) 

The dataset was uploaded like a datatable class, and the mentiones options didn't work.

Does anyone know any solutions on this issue?

  • 1
    Are you assigning the result of `as.numeric()` back to the column? For example `df$column1 <- as.numeric(df$column1)`. – neilfws Nov 23 '21 at 22:12
  • I only try to convert using: `as.numeric(df$column1)` , but the vector values were converted to `NA`. – Alex Amaguaya Nov 24 '21 at 03:42
  • 3
    @Alex can you please share the structure of the data read? Also check the separator in the csv file because by default fread considers comma as the separator and if the separator is different then you will have to specify it while reading the file. – Isa Nov 24 '21 at 10:58
  • 1
    The reason that a number would be read in as a string is either something in the file is corrupting that column or you used incorrect arguments to `fread`. While fixing the data here will resolve this *symptom*, you are still corrupting the data somehow. Please make this question more reproducible by including sample data (including a sample of the raw CSV file contents) and the code you used to read it in. Please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Dec 15 '21 at 13:58

0 Answers0