Forum: help
Monitor Forum | Start New ThreadRE: Importing csv file into R - numeric values read as characters [ Reply ] By: Kumar on 2017-07-06 16:55 | [forum:45228] |
Oops found the issue. Amount was separated by , and that's why it was getting imported as string. Thank you all. |
RE: Importing csv file into R - numeric values read as characters [ Reply ] By: Adrian Dusa on 2017-07-06 16:48 | [forum:45227] |
There is no attachment, perhaps RForge doesn't deal with attachments properly. Another guess is the scientific notation of a number, something like "1e+06" instead of 1000000. As mentioned in my previous email, post the result of the command: > head(myDataFrame) |
RE: Importing csv file into R - numeric values read as characters [ Reply ] By: Kumar on 2017-07-06 16:44 | [forum:45226] |
Added the attachment. Currency is not there but symbol " is getting added to amount. How to remove that character from csv file before importing into R. |
RE: Importing csv file into R - numeric values read as characters [ Reply ] By: Adrian Dusa on 2017-07-06 16:36 | [forum:45225] |
Cannot access your file, so only guessing what's going on. To get a better idea, you could post the output after: > myDataFrame <- read.csv("somm.csv", header=TRUE, sep=delim, dec=dec, stringsAsFactors=FALSE) > head(myDataFrame) For now, it really depends on how your input data looks like, I'm guessing it has the currency added (likely by Excel or something similar). > as.numeric("$4") [1] NA Warning message: NAs introduced by coercion |
Importing csv file into R - numeric values read as characters [ Reply ] By: Kumar on 2017-07-06 16:24 | [forum:45224] somm.csv (49) downloads |
I have a csv file which I read using below commands: delim = "," # or is it "\t" ? dec = "." # or is it "," ? myDataFrame <- read.csv("somm.csv", header=TRUE, sep=delim, dec=dec, stringsAsFactors=FALSE) Amount is getting imported as char. then i execute below command to convert it to numeric: myDataFrame$column.name <- as.numeric(data$column.name) But after executing above line, all the values in Amount becomes NA. Any idea what I am doing wrong. |