Search code examples
rscientific-notation

Removing scientific notation format from character column type


I have an issue where I have a column in a dataframe that is a character type as there is text in it so I cannot force it to be numeric. But I also have values that show up as scientific notation that I would like to convert and remove the scientific notation.

In the data assume there is an unknown amount of these values that need to be converted. How best can I remove the scientific notation from this type of data?

Example data:

vector <- c("HMM","5.8779396207367296E+17","GOLF","3191963","355534317","8.837971002284400E+16")
exampledf <- as.data.frame(vector)

what I would like it to look like:

vector <- c("HMM","587793962073672960","GOLF","3191963","355534317","80837971002284400")

Solution

  • You can use type.convert:

    as.character(type.convert(as.list(vector), as.is = TRUE))
    #[1] "HMM" "587793962073672960" "GOLF" "3191963" "355534317" "88379710022844000"