We were not told this was a matrix, rather a 'dataset'.
If it is matrix, logical indexing via is.na(x) is pretty good, although it
will create an index equal in size to the dataset (but logical).
If 'dataset' means a data frame, you will use less memory using a for()
loop over columns, e.g.
If your matrix is 835353x86, then if it is numeric, then it will take
about 550MB for a single copy. You should therefore have at least 2GB
(so you can have a couple of copies as part of some processing) of
real memory on your system. If you want to replace NAs with zero,
then this is how you mig
L PROTECTED]
Namens Denise Xifara
Verzonden: maandag 28 juli 2008 15:15
Aan: r-help@r-project.org
Onderwerp: [R] speeding up loop and dealing wtih memory problems
Dear All and Mark,
Given a dataset that I have called dat, I was hoping to speed up the
following loop:
for(i in 1:835353){
for(j in 1:86){
Is it what you want ?
> x <- matrix(c(1:3, NA, NA, 4, 1:2, NA), 3, 3)
> x
[,1] [,2] [,3]
[1,]1 NA1
[2,]2 NA2
[3,]34 NA
> x[is.na(x)] <- 0
> x
[,1] [,2] [,3]
[1,]101
[2,]202
[3,]340
2008/7/28 Denise Xifara <[EMAIL PROTECT
Dear All and Mark,
Given a dataset that I have called dat, I was hoping to speed up the
following loop:
for(i in 1:835353){
for(j in 1:86){
if (is.na(dat[i,j])==TRUE){dat[i,j]<-0 }}}
Actually I am also having a memory problem. I get the following:
Error: cannot allocate vector of size 3.2 Mb
5 matches
Mail list logo