[R] (subscript) logical subscript too long

Giorgio Garziano
Thu, 01 Oct 2015 11:37:25 -0000

Check your memory size by:

memory.limit()

try to increase it by:

memory.limit(size=4096)



From: Maram SAlem [mailto:marammagdysalem at gmail.com]
Sent: gioved? 1 ottobre 2015 13:22
To: Giorgio Garziano
Cc: r-help at r-project.org
Subject: Re: [R] (subscript) logical subscript too long

Thanks Giorgio, I got it.

 I managed to reach the matrix s whose rows represent  all the possible
combinations. Here is the code:

> n=12
> m=7
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))
> ED<-as.matrix(ED)
> lk<-which(rowSums(ED)<=(n-m))
> s<-ED[lk,]

The problem now is that the code works only for relatively small values of n and
m, but when I use, for ex., n=20 and m=9, I got this error

> n=20
> m=9
> D<-matrix(0,nrow=n-m+1,ncol=m-1)
> for (i in 1:m-1)
+  {
+ D[,i]<-seq(0,n-m,1)
+  }
> ED <- do.call(`expand.grid`,as.data.frame(D))

Error: cannot allocate vector of size 1.6 Gb

Any Suggestions please?

Thanks Again.
Maram

On 30 September 2015 at 17:41, Giorgio Garziano <giorgio.garziano at
ericsson.com<mailto:giorgio.garziano at ericsson.com>> wrote:
Be:

log <- (rowSums(ED) <= (n - m))


Compare the following two values:





length(log)





nrow(w)





--

GG


        [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


	[[alternative HTML version deleted]]