0

MergeData is a very large matrix, I am trying to replace Na with 0 I did some "googling" and found that the code below would do that but it does not work because I get

MergedData[is.na(MergedData)] <- 0

Warning message:
In `[<-.factor`(`*tmp*`, thisvar, value = 0) :
  invalid factor level, NA generated

Further research had me doing for loops but I'm still not getting it. Any recommendations on how to do this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    Your proposed code should work if `MergedData` really were a matrix. It's not. Check the class and structure of your object for starters. – John Oct 15 '15 at 05:50
  • @RichardScriven Okay, my mistake then – akrun Oct 15 '15 at 05:55
  • OK, yes, my mistake. A matrix that was entirely a factor would have this problem. However, given the more common R mistakes, a data.frame is more likely to be part of the problem here. Knowing the structure of the MergedData object would help in not having to guess at the answer. – John Oct 15 '15 at 06:08
  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). This will make it much easier for others to help you. – Jaap Oct 15 '15 at 06:35
  • Is there any way i can look through my data frame and regardless on what each variable(col) is factor, integer, numeric just search for na's and replacing them with zero? I'm new to R and I've looked and tried many codes found online but no help. This seems to me like a common question and i don't know if I'm not being clear enough.. thanks – Diego Salazar Oct 16 '15 at 01:51

0 Answers0