I have a UTF-16 Unicode Text (.txt) file downloaded and defaulted as comma-separated values (.csv) when saved on a mac drive. This file contains numeric data that has 1000 separator applied for numbers that are greater than 1,000. When loading in R, this data is in character class. In order to convert to numeric class, I do the following:
tx <- read.table("/Users/username/Desktop/report.csv",sep="\t", dec = ".", fileEncoding = "UTF-16LE", fill = T, skip=1 , quote="", header=T, stringsAsFactors = FALSE)
tx$Cost <- gsub("\\,", replacement = "", x = tx$Cost)
tx$Cost <- as.numeric(tx$Cost)
Warning message:
NAs introduced by coercion
When summarized using the head(subset()) function, the following is the result where I'm still not able to convert into numeric class:
**Orig after_gsub as.numeric**
1 95.31 95.31 95.31
2 992.77 992.77 992.77
3 "1,719.68" "1719.68" NA
4 "3,135.79" "3135.79" NA
5 111.91 111.91 111.91
6 305.12 305.12 305.12
Can someone help me convert them into numeric class using as.numeric()?