Hello r-help, why call: #---------- outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0,.0001,m[r,c]) ) #---------- for matrix m with only 1000 rows and 2 columns forces my PC to use more than 250Mb(!) of virtual memory? strange... -- Best regards, Valery A.Khamenya mailto:news_vkhamenya at chat.ru -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 22 Mar 2001 news_vkhamenya at chat.ru wrote:> Hello r-help, > > why call: > > #---------- > outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0,.0001,m[r,c]) ) > #---------- > > for matrix m with only 1000 rows and 2 columns forces my PC to use > more than 250Mb(!) of virtual memory? strange...Um, a strange use of outer. Try m[m <= 0] <- 0.0001 for an efficient solution. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello Brian D. Ripley and r-help, Thursday, March 22, 2001, 11:49:55 AM, you wrote: 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]) ) #------- ? P.S. however, "out of virtual memory" stil there... and is not motivated yet. Maybe it is some kind of bug -- Best regards, Valery A.Khamenya mailto:news_vkhamenya at chat.ru -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: news_vkhamenya at chat.ru > Date: Thu, 22 Mar 2001 13:24:53 +0300 > > Hello Brian D. Ripley and r-help, > > Thursday, March 22, 2001, 11:49:55 AM, you wrote: > > 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]) ) > #------- > ? > > P.S. however, "out of virtual memory" stil there... and is not > motivated yet. Maybe it is some kind of bugNo, it is a misuse of R. You do need to learn how to use indexing .... If you ask for thousands of copies of objects, you get them. Please do read the section on BUGS in the FAQ. Not doing what you expect is not a bug ..... -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
news_vkhamenya at chat.ru wrote:> Hello r-help, > > why call: > > #---------- > outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0,.0001,m[r,c]) ) > #---------- > > for matrix m with only 1000 rows and 2 columns forces my PC to use > more than 250Mb(!) of virtual memory? strange... >I think the source of the confusion here is in how outer uses its FUN argument, and hence how that function has to be written. Here is an example that should show what is happening:> f<-function(x,y) {+ cat("x = ", x, "\n") + cat("y = ", y, "\n") + x+y + }> outer(1:3,1:2,f)x = 1 2 3 1 2 3 y = 1 1 1 2 2 2 [,1] [,2] [1,] 2 3 [2,] 3 4 [3,] 4 5>[instead of printing, you can also use debug(f) to see what is going on] There is *one* call to FUN with arguments that are the appropriate replications of X and Y, not 3*2=6 calls to FUN with scalar arguments. This is done since one call to a vectorized function will be much faster than many calls to functions working with scalar values. The help for outer hints at this but could be a bit more explicit on this since it is a natural point of confusion. As a result, as has been pointed out by others, outer isn't the right tool for this problem. Hope that helps. luke -- Luke Tierney University of Minnesota Phone: 612-625-7843 School of Statistics Fax: 612-624-8868 313 Ford Hall, 224 Church St. S.E. email: luke at stat.umn.edu Minneapolis, MN 55455 USA WWW: http://www.stat.umn.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 08:49 22/03/01 +0000, Prof Brian D Ripley wrote:>On Thu, 22 Mar 2001 news_vkhamenya at chat.ru wrote: > >> Hello r-help, >> >> why call: >> >> #---------- >> outer(1:1000, 1:2, function(r,c) ifelse(m[r,c]<=0,.0001,m[r,c]) ) >> #---------- >> >> for matrix m with only 1000 rows and 2 columns forces my PC to use >> more than 250Mb(!) of virtual memory? strange... > >Um, a strange use of outer. Try > >m[m <= 0] <- 0.0001 > >for an efficient solution. > >--I have also had problems with outer:> m<-matrix(rnorm(6),3,2);m[,1] [,2] [1,] -0.4678067 0.6257795 [2,] 1.3981146 0.6273542 [3,] -0.3987765 1.6764002> outer(1:3,1:2,function(r,c){paste(r,c)})[,1] [,2] [1,] "1 1" "1 2" [2,] "2 1" "2 2" [3,] "3 1" "3 2"> outer(1:3,1:2,function(r,c){m[r,c]})[,1] [,2] [1,] -0.4678067 -0.4678067 [2,] 1.3981146 1.3981146 [3,] -0.3987765 -0.3987765 I should get m here, but I get first column twice. (R 1.2.2, w95) --------------------------------------------------- Javier Mu?oz Criado Delegado Provincial Instituto Nacional de Estad?stica C/ Cura 7 - 02071 Albacete - Espa?a Tel 967 219 230 - Fax 967 216 649 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._