I'm trying to replace NA in matrix - mat
- by zeros. I'm using mat[is.na(mat)] <- 0
. When I have matrix of 94531 observations of 18946 variables or smaller it works good but I try it on matrix of 112039 observations of 22752 variables, R shows an error:
Error in if (!nreplace) return(x) : missing value where TRUE/FALSE needed
In addition: Warning message:
In sum(i, na.rm = TRUE) : integer overflow - use sum(as.numeric(.))
I don't know what I'm doing wrong and I don't understand the error.
Here is an example of the structure of my data.
small data.matrix: (made from real data source)
> str(mat)
Classes 'data.table' and 'data.frame': 94531 obs. of 18946 variables:
$ 6316506: num 1 0 NA NA NA NA NA NA NA NA ...
$ 6794602: num 0 1 NA NA NA NA NA 0 0 0 ...
$ 1008667: num NA NA 0 1 0 NA NA 0 0 0 ...
$ 6312454: num NA NA 1 0 0 NA NA 0 0 0 ...
$ 8009082: num NA NA 0 0 1 NA NA NA NA NA ...
$ 1023293: num NA NA NA NA NA 1 NA NA NA NA ...
$ 6740421: num NA NA NA NA NA 1 NA 0 0 0 ...
$ 6777805: num NA NA NA NA NA NA 1 NA NA NA ...
$ 1000558: num NA NA NA NA NA NA NA 0 0 0 ...
$ 1001682: num NA NA NA NA NA NA NA 0 0 0 ...
the bigger looks exactly the same.
Other question:
is there some way how to use rbindlist(data, fill=T)
and fill with zeros instead of NAs?