0

I have a dataframe with sales of 896 items from Monday to Saturday. Inside, there are some NA values and numbers such as for example $2,796.21. I read the txt file with:

mega1 <- read.table("Report-WEEK 24112014.txt", sep=",", stringsAsFactors = FALSE, header = FALSE)

I want to get rid of the the NA values, the "$" and "," characters so I can perform my sales analysis. I used:

mega1[is.na(mega1)] <- 0   # to replace the NAs by 0
mega1$Monday <- as.numeric(sub("\\$" ,"", mega1$Monday)) #as the same for the other days 

but R gave me: Warning message: NAs introduced by coercion and the numbers such as $2796.21 has changed to NA.

I would like some help. Thanks!

parakmiakos
  • 2,994
  • 9
  • 29
  • 43
SamyR9
  • 1
  • 1
    Let's see a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). My suspicion is that R doesn't know how to coerce `2,100.00` to numeric. In that case, you should probably `gsub` out the comma, too (using something like `\\$|,`). – Roman Luštrik Dec 09 '14 at 13:32
  • and with `sep=","`, you'll run into trouble as well... – Berry Boessenkool Dec 09 '14 at 13:41

0 Answers0