0

I have csv spreadsheet with hude dataset. as part of cleaning the data I have to replace the negative values with NA so when I use average function of any statistics these negative values can be ignored by R. I am using R and would appreciate if someone can provide an easier way to deal with instead of trying to work on each individual columns and rows and then using rbind or cbind.

OTStats
  • 1,820
  • 1
  • 13
  • 22
raj ag
  • 1
  • Does this answer your question? [Replace all 0 values to NA](https://stackoverflow.com/questions/11036989/replace-all-0-values-to-na) – RLave Jan 14 '20 at 09:59

2 Answers2

0

This can actually be done quickly using Google Sheets or Microsoft Excel, no need to use R for this.

  1. Load the CSV file onto Google Sheets or Excel.
  2. Turn the fitlers on.
  3. Filter the column you wanted to look for negative values using "Filter by condition"
  4. Change all the filtered values to NA and save that CSV.
  5. Export the CSV as the filters turned you file into a Google Sheets file or an excel file.

Now you can just use that csv file in R.

0

If you are using R for the manipulation, then you can simply write a condition in R to ignore the negative values from the CSV when you are calculating the statistics. If your csv file is heavy, I would say this would be easier than manipulating the csv file. You could use something like the below:

df[df < 0] <- NA
CR7SMS
  • 2,520
  • 1
  • 5
  • 13