0

I believe this is an old question, but I haven't found any answers to my condition. I have a list of values. The values are in double format, but are usually less than 20. There are some values -99.9. How to replace the -99.9 to NA, and calculate average values from this list without considering these NA values? I tried lapply, but I don't know how to write the function properly. Thanks for your help.

mountain_sn
  • 53
  • 1
  • 2
  • 10
  • `L[L == -99.9] <- NA`? – Joe Feb 20 '15 at 21:00
  • Thanks, Joe. I tried this code, but all the numbers maintain the same in the list. So this doesn't work. – mountain_sn Feb 20 '15 at 21:03
  • 1
    Can you post a [reproducible example](http://stackoverflow.com/a/5963610/3204472)? Using a very simple list (`L <- list(1, 2, -99.9`), my suggestion worked for me. – Joe Feb 20 '15 at 21:07
  • Thanks, I just checked the dataset type, and it is double. I converted it by using as.list, but the method above still doesn't work. Is there anything wrong with the step? – mountain_sn Feb 20 '15 at 21:11
  • Testing for equality with floats isn't a good idea. Test a range of values. – Dason Feb 20 '15 at 21:43
  • I'm not testing it, I really have this problem and worried. But some people gave comments earlier may think I'm not serious about it. – mountain_sn Feb 20 '15 at 22:09

1 Answers1

0

The problem has been solved. I changed the code from vec==-99.9 to vec <0, because all other values are higher than 0. Though I don't know why the former problem happened.

mountain_sn
  • 53
  • 1
  • 2
  • 10