[R] out of memory?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Mar 22 12:38:48 CET 2001


news_vkhamenya at chat.ru writes:

> PBDR> Um, a strange use of outer. Try
> PBDR> m[m <= 0] <- 0.0001
> PBDR> for an efficient solution.
> 
> thank you for a good solution, it helps. but what if I need
> #--------
> outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0, some_f(m[r,c]), m[r,c]) )
> #-------
> ?

m[m <= 0] <- some_f(m[m <= 0])

*provided* that some_f vectorizes properly. You may need

m[m <= 0] <- sapply(m[m <= 0], some_f)

> P.S. however, "out of virtual memory" stil there... and is not
>      motivated yet. Maybe it is some kind of bug

Experiment with a smaller matrix, and you'll see the error of your ways:

> m<-matrix(1:10,5,2)
> outer(1:5,1:2,function(r,c){print(m[r,c]);m[r,c]})
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    1    1    1    1    6    6    6    6     6
 [2,]    2    2    2    2    2    7    7    7    7     7
 [3,]    3    3    3    3    3    8    8    8    8     8
 [4,]    4    4    4    4    4    9    9    9    9     9
 [5,]    5    5    5    5    5   10   10   10   10    10
 [6,]    1    1    1    1    1    6    6    6    6     6
 [7,]    2    2    2    2    2    7    7    7    7     7
 [8,]    3    3    3    3    3    8    8    8    8     8
 [9,]    4    4    4    4    4    9    9    9    9     9
[10,]    5    5    5    5    5   10   10   10   10    10
     [,1] [,2]
[1,]    1    1
[2,]    2    2
[3,]    3    3
[4,]    4    4
[5,]    5    5

(If there is a bug, it is in array() not complaining when its data=
argument is getting truncated).

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list