# Speeding up a loop Classic List Threaded 18 messages Open this post in threaded view
|

## Speeding up a loop

 General problem: I have 20 projects that can be invested in and I need to decide which combinations meet a certain set of standards. The total possible combinations comes out to 2^20. However I know for a fact that the number of projects must be greater than 5 and less than 13. So far the the code below is the best I can come up with for iteratively creating a set to check against my set of standards. Code x<-matrix(0,nrow=1,ncol=20) for(i in 1:2^20) { x<-x+1   for(j in 1:20)   {     if(x[j]>1)     {       x[j]=0       if(j<20)       {         x[j+1]=x[j+1]+1       }     }   } if(sum(x)>5 && sum(x)<13) { # insert criteria here. } } my code forces me to create all 2^20 x's and then use an if statement to decide if x is within my range of projects. Is there a faster way to increment x. Any ideas on how to kill the for loop so that it won't attempt to process an x where the sum is greater than 12 or less than 6?
Open this post in threaded view
|

## Re: Speeding up a loop

 I've had to do something similar, so I wrote a small function to help. This runs in about 1/4 the time of your code on my machine. Others may have a more efficient approach. all.combs <- function(num, from=0, to=num) {         # create a matrix of all possible combinations of num items         # restrict each row to have between "from" and "to" items         res <- vector("list", to-from+1)         for(i in seq(from:to)) {                 j <- (from:to)[i]                 if(j==0) res[[i]] <- rep(FALSE, num)                 comb <- combn(num, j)                 res[[i]] <- t(apply(comb, 2, function(x) !is.na(match(1:num, x))))                 }         do.call(rbind, res)         } all.combs(20, 5, 13) Jean wwreith <[hidden email]> wrote on 07/20/2012 07:45:30 AM: > General problem: I have 20 projects that can be invested in and I need to > decide which combinations meet a certain set of standards. The total > possible combinations comes out to 2^20. However I know for a fact that the > number of projects must be greater than 5 and less than 13. So far the the > code below is the best I can come up with for iteratively creating a set to > check against my set of standards. > > Code > x<-matrix(0,nrow=1,ncol=20) > for(i in 1:2^20) > { > x<-x+1 >   for(j in 1:20) >   { >     if(x[j]>1) >     { >       x[j]=0 >       if(j<20) >       { >         x[j+1]=x[j+1]+1 >       } >     } >   } > if(sum(x)>5 && sum(x)<13) > { > # insert criteria here. > } > } > > my code forces me to create all 2^20 x's and then use an if statement to > decide if x is within my range of projects. Is there a faster way to > increment x. Any ideas on how to kill the for loop so that it won't attempt > to process an x where the sum is greater than 12 or less than 6?         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 In reply to this post by wwreith On Fri, Jul 20, 2012 at 05:45:30AM -0700, wwreith wrote: > General problem: I have 20 projects that can be invested in and I need to > decide which combinations meet a certain set of standards. The total > possible combinations comes out to 2^20. However I know for a fact that the > number of projects must be greater than 5 and less than 13. So far the the > code below is the best I can come up with for iteratively creating a set to > check against my set of standards. > > Code > x<-matrix(0,nrow=1,ncol=20) > for(i in 1:2^20) > { > x<-x+1 >   for(j in 1:20) >   { >     if(x[j]>1) >     { >       x[j]=0 >       if(j<20) >       { >         x[j+1]=x[j+1]+1 >       } >     } >   } > if(sum(x)>5 && sum(x)<13) > { > # insert criteria here. > } > } > > my code forces me to create all 2^20 x's and then use an if statement to > decide if x is within my range of projects. Is there a faster way to > increment x. Any ideas on how to kill the for loop so that it won't attempt > to process an x where the sum is greater than 12 or less than 6? Hi. The restriction on the sum of the rows between 6 and 12 eliminates the tails of the distribution, not the main part. So, the final number of rows is not much smaller than 2^20. More exactly, it is   sum(choose(20, 6:12)) which is about 0.8477173 * 2^20. On the other hand, all combinations may be created using expand.grid() faster than using a for loop. Try the following   g <- as.matrix(expand.grid(rep(list(0:1), times=20)))   s <- rowSums(g)   x <- g[s > 5 & s < 13, ]   nrow(x)    888896 Hope this helps. Petr Savicky. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 Petr, This is great. MUCH faster than the code I provided. And much more elegant code. Thanks for posting! Jean Petr Savicky <[hidden email]> wrote on 07/20/2012 09:26:34 AM: > On Fri, Jul 20, 2012 at 05:45:30AM -0700, wwreith wrote: > > General problem: I have 20 projects that can be invested in and I need to > > decide which combinations meet a certain set of standards. The total > > possible combinations comes out to 2^20. However I know for a fact that the > > number of projects must be greater than 5 and less than 13. So far the the > > code below is the best I can come up with for iteratively creating a set to > > check against my set of standards. > > > > Code > > x<-matrix(0,nrow=1,ncol=20) > > for(i in 1:2^20) > > { > > x<-x+1 > >   for(j in 1:20) > >   { > >     if(x[j]>1) > >     { > >       x[j]=0 > >       if(j<20) > >       { > >         x[j+1]=x[j+1]+1 > >       } > >     } > >   } > > if(sum(x)>5 && sum(x)<13) > > { > > # insert criteria here. > > } > > } > > > > my code forces me to create all 2^20 x's and then use an if statement to > > decide if x is within my range of projects. Is there a faster way to > > increment x. Any ideas on how to kill the for loop so that it won't attempt > > to process an x where the sum is greater than 12 or less than 6? > > Hi. > > The restriction on the sum of the rows between 6 and 12 eliminates the > tails of the distribution, not the main part. So, the final number of > rows is not much smaller than 2^20. More exactly, it is > >   sum(choose(20, 6:12)) > > which is about 0.8477173 * 2^20. On the other hand, all combinations > may be created using expand.grid() faster than using a for loop. > > Try the following > >   g <- as.matrix(expand.grid(rep(list(0:1), times=20))) >   s <- rowSums(g) >   x <- g[s > 5 & s < 13, ] >   nrow(x) > >    888896 > > Hope this helps. > > Petr Savicky.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 In reply to this post by Petr Savicky On Fri, Jul 20, 2012 at 04:26:34PM +0200, Petr Savicky wrote: > On Fri, Jul 20, 2012 at 05:45:30AM -0700, wwreith wrote: > > General problem: I have 20 projects that can be invested in and I need to > > decide which combinations meet a certain set of standards. The total > > possible combinations comes out to 2^20. However I know for a fact that the > > number of projects must be greater than 5 and less than 13. So far the the > > code below is the best I can come up with for iteratively creating a set to > > check against my set of standards. > > > > Code > > x<-matrix(0,nrow=1,ncol=20) > > for(i in 1:2^20) > > { > > x<-x+1 > >   for(j in 1:20) > >   { > >     if(x[j]>1) > >     { > >       x[j]=0 > >       if(j<20) > >       { > >         x[j+1]=x[j+1]+1 > >       } > >     } > >   } > > if(sum(x)>5 && sum(x)<13) > > { > > # insert criteria here. > > } > > } > > > > my code forces me to create all 2^20 x's and then use an if statement to > > decide if x is within my range of projects. Is there a faster way to > > increment x. Any ideas on how to kill the for loop so that it won't attempt > > to process an x where the sum is greater than 12 or less than 6? > > Hi. > > The restriction on the sum of the rows between 6 and 12 eliminates the > tails of the distribution, not the main part. So, the final number of > rows is not much smaller than 2^20. More exactly, it is > >   sum(choose(20, 6:12)) > > which is about 0.8477173 * 2^20. On the other hand, all combinations > may be created using expand.grid() faster than using a for loop. > > Try the following > >   g <- as.matrix(expand.grid(rep(list(0:1), times=20))) >   s <- rowSums(g) >   x <- g[s > 5 & s < 13, ] Hi. The above code creates a matrix, whose rows are vectors of 0,1, which contain between 6 and 12 ones. Using this matrix, it is possible to go through all these combinations using a for loop as follows.   for (i in seq.int(length=nrow(x))) {       here, x[i, ] is a row of the matrix   } Another option is to use ifelse() function, which allows to evaluate a condition on the whole columns of the matrix. If this is possible, then it is more efficient than a for loop. Instead of using expand.grid() to create all 2^20 combinations, it is possible to create only rows with a specified number of ones. The rows of length n with exactly k ones can be created as follows.   n <- 5   k <- 2   ind <- combn(n, k)   m <- ncol(ind)   x <- matrix(0, nrow=m, ncol=n)   x[cbind(rep(1:m, each=k), c(ind))] <- 1   x    [1,]    1    1    0    0    0    [2,]    1    0    1    0    0    [3,]    1    0    0    1    0    [4,]    1    0    0    0    1    [5,]    0    1    1    0    0    [6,]    0    1    0    1    0    [7,]    0    1    0    0    1    [8,]    0    0    1    1    0    [9,]    0    0    1    0    1   [10,]    0    0    0    1    1 Hope this helps. Petr Savicky. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 In reply to this post by wwreith "Reith, William [USA]" <[hidden email]> wrote on 07/20/2012 09:52:02 AM: > Would this matrix eat up memory making the rest of my program > slower? Each x needs to be multiplied by a matrix and the results > checked against a set of thresholds. Doing them one at a time takes > at least 24 hours right now. > > Optimizing a program is not my thing. > > Sent from my Verizon Wireless 4GLTE smartphone It's not mine either. Better to ask the group. I'm ccing R-help on this message. Jean > "Jean V Adams" <[hidden email]> wrote on 07/20/2012 10:05 AM: > > I've had to do something similar, so I wrote a small function to help. > This runs in about 1/4 the time of your code on my machine. > Others may have a more efficient approach. > > all.combs <- function(num, from=0, to=num) { >         # create a matrix of all possible combinations of num items >         # restrict each row to have between "from" and "to" items >         res <- vector("list", to-from+1) >         for(i in seq(from:to)) { >                 j <- (from:to)[i] >                 if(j==0) res[[i]] <- rep(FALSE, num) >                 comb <- combn(num, j) >                 res[[i]] <- t(apply(comb, 2, function(x) !is.na > (match(1:num, x)))) >                 } >         do.call(rbind, res) >         } > > all.combs(20, 5, 13) > > Jean > > > wwreith <[hidden email]> wrote on 07/20/2012 07:45:30 AM: > > > General problem: I have 20 projects that can be invested in and I need to > > decide which combinations meet a certain set of standards. The total > > possible combinations comes out to 2^20. However I know for a fact that the > > number of projects must be greater than 5 and less than 13. So far the the > > code below is the best I can come up with for iteratively creating a set to > > check against my set of standards. > > > > Code > > x<-matrix(0,nrow=1,ncol=20) > > for(i in 1:2^20) > > { > > x<-x+1 > >   for(j in 1:20) > >   { > >     if(x[j]>1) > >     { > >       x[j]=0 > >       if(j<20) > >       { > >         x[j+1]=x[j+1]+1 > >       } > >     } > >   } > > if(sum(x)>5 && sum(x)<13) > > { > > # insert criteria here. > > } > > } > > > > my code forces me to create all 2^20 x's and then use an if statement to > > decide if x is within my range of projects. Is there a faster way to > > increment x. Any ideas on how to kill the for loop so that it won't attempt > > to process an x where the sum is greater than 12 or less than 6?         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 That is faster than what I was doing and reducing 15% of my iterations it still very helpful. Next question. I need to multiply each row x[i,] of the matrix x by another matrix A. Specifically for(i in 1:n) { If (x[i,]%*%A[,1]<.5 || x[i,]%*%A[,2]<42 || x[i,]%*%A[,3]>150) { x<-x[-i,] n<-n-1 }. #In other words remove row i from x if it does not meet criteria (>=.5, >=42, <=150). When multiplied to A } Is there a better way than using a for loop for this or x<-x[-i,] for that matter? I assume building a new matrix would be worse. Ideally I want to also exclude some x[,i] as well example if x[1,] is better than x[2,] in all three categories i.e. bigger, bigger, and smaller than x[2,] when multiplied to A then I want to exclude x[2,] as well. Any suggestions on whether it is better to do this all at once or in stages? Thanks for helping!
Open this post in threaded view
|

## Re: Speeding up a loop

 This works to multiply the ith row of a by the ith value of b. It might be what you can use a <- matrix(1:30, 6, 5) b <- 1:6 a a*b To simplify your code, I think you can do this---one multiplication xA <- x %*% A Now you can do the tests on xA and not have any matrix multiplications inside the loop. The next line is not tested but I hope gives you the idea remove.set <- (xA[,1] < .5) || (xA[,2] < 52) || (xA[,3] > 150) new.x <- x[remove.set,] You now have new.x with no explicit loops at all, because this takes advantage of vector operations. Rich On Fri, Jul 20, 2012 at 2:34 PM, wwreith <[hidden email]> wrote: > That is faster than what I was doing and reducing 15% of my iterations it > still very helpful. > > Next question. > > I need to multiply each row x[i,] of the matrix x by another matrix A. > Specifically > > for(i in 1:n) > { > If (x[i,]%*%A[,1]<.5 || x[i,]%*%A[,2]<42 || x[i,]%*%A[,3]>150) > { > x<-x[-i,] > n<-n-1 > }. #In other words remove row i from x if it does not meet criteria (>=.5, > >=42, <=150). When multiplied to A > } > Is there a better way than using a for loop for this or x<-x[-i,] for that > matter? I assume building a new matrix would be worse. > > Ideally I want to also exclude some x[,i] as well example if x[1,] is > better > than x[2,] in all three categories i.e. bigger, bigger, and smaller than > x[2,] when multiplied to A then I want to exclude x[2,] as well. Any > suggestions on whether it is better to do this all at once or in stages? > > Thanks for helping! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637255.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > 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]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 whoops, backwards new.x <- x[!remove.set,] On Fri, Jul 20, 2012 at 2:51 PM, Richard M. Heiberger <[hidden email]>wrote: > This works to multiply the ith row of a by the ith value of b. > It might be what you can use > > a <- matrix(1:30, 6, 5) > b <- 1:6 > > a > a*b > > > > To simplify your code, I think you can do this---one multiplication > > xA <- x %*% A > > Now you can do the tests on xA and not have any matrix multiplications > inside the loop. > The next line is not tested but I hope gives you the idea > > remove.set <- (xA[,1] < .5) || (xA[,2] < 52) || (xA[,3] > 150) > > new.x <- x[remove.set,] > > You now have new.x with no explicit loops at all, because this takes > advantage of vector operations. > > Rich > > On Fri, Jul 20, 2012 at 2:34 PM, wwreith <[hidden email]> wrote: > >> That is faster than what I was doing and reducing 15% of my iterations it >> still very helpful. >> >> Next question. >> >> I need to multiply each row x[i,] of the matrix x by another matrix A. >> Specifically >> >> for(i in 1:n) >> { >> If (x[i,]%*%A[,1]<.5 || x[i,]%*%A[,2]<42 || x[i,]%*%A[,3]>150) >> { >> x<-x[-i,] >> n<-n-1 >> }. #In other words remove row i from x if it does not meet criteria (>=.5, >> >=42, <=150). When multiplied to A >> } >> Is there a better way than using a for loop for this or x<-x[-i,] for that >> matter? I assume building a new matrix would be worse. >> >> Ideally I want to also exclude some x[,i] as well example if x[1,] is >> better >> than x[2,] in all three categories i.e. bigger, bigger, and smaller than >> x[2,] when multiplied to A then I want to exclude x[2,] as well. Any >> suggestions on whether it is better to do this all at once or in stages? >> >> Thanks for helping! >> >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637255.html>> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] mailing list >> 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]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 next for loop question. I need a loop that removes a row from a matrix if it is worse in positions 1,2,3,4 than another row in the matrix. right now my matrix is 503028x26. Rule to define worse position1 is smaller, position2 is smaller, position3 is higher, and position4 is smaller Example: row1: 1, 10, 3, 3 row2: 3, 7, 5, 2 row2 is not worse than row1 since it is "better" in position 1, eventhough it is worse in all other positions. row3: 2,5,7,1 row3 however is worse than row2 and should be removed from the matrix. Any ideas? Should I break this into pieces or do it all at once? Is there something faster than a loop? My current loops takes well over 24 hours to run. m<-matrix(0,1,24) for(i in 1:n) {  a<-matrix(x[i,1:4],1,4) j=1       nn<-nrow(m)       counter<-0       while(j<=nn)       {         if(a>m[j,1] && a>m[j,2] && a>m[j,4] && amin(m[,1]) || a>min(m[,3]) || a>min(m[,4]) || a
Open this post in threaded view
|

## Re: Speeding up a loop

 Hello, Maybe it would have been better to start a new thread, if the question is different. To show that it's a continuation, the subject line could be extended with "part 2" or something like that. This solution runs in 3.6 hours. to.keep <- function(x){      keep <- function(i, env){          env\$ires <- env\$ires + 1          if(env\$ires > env\$curr.rows){              env\$result <- rbind(env\$result, matrix(nrow=increment, ncol=nc))              env\$curr.rows <- env\$curr.rows + increment          }          env\$result[env\$ires, ] <- x[i, ]      }      a1 <- x[, 1]      a2 <- x[, 2]      a3 <- x[, 3]      a4 <- x[, 4]      nc <- ncol(x)      increment <- 1000      e <- new.env()      e\$curr.rows <- increment      e\$result <- matrix(nrow=e\$curr.rows, ncol=nc)      e\$ires <- 0      for(i in seq_len(nrow(x))){          yes <- x[i, 1] >= a1 | x[i, 2] >= a2 | x[i, 3] <= a3 | x[i, 4]  >= a4          if(all(yes)) keep(i, e)      }      e\$result[seq_len(e\$ires), 1:nc] } # Now the timing. set.seed(3971) nc <- 26 Enes <- seq(from=1e3, to=1e4, by=1e3) tm <- numeric(length(Enes)) i <- 0 for(n in Enes){      i <- i + 1      N <- nc*n      m <- matrix(sample(0:9, N, TRUE), ncol=nc)      tm[i] <- system.time(kp <- to.keep(m)) } plot(Enes, tm) # quadratic behavior fit <- lm(tm ~ Enes + I(Enes^2)) (secs <- predict(fit, newdata=data.frame(Enes=503028))) secs/60/60 # 3.6 hours Hope this helps, Rui Barradas Em 21-07-2012 13:26, wwreith escreveu: > next for loop question. > > I need a loop that removes a row from a matrix if it is worse in positions > 1,2,3,4 than another row in the matrix. right now my matrix is 503028x26. > > Rule to define worse position1 is smaller, position2 is smaller, position3 > is higher, and position4 is smaller > > Example: > > row1: 1, 10, 3, 3 > row2: 3, 7, 5, 2 > > > row2 is not worse than row1 since it is "better" in position 1, eventhough > it is worse in all other positions. > > row3: 2,5,7,1 > row3 however is worse than row2 and should be removed from the matrix. > > Any ideas? Should I break this into pieces or do it all at once? Is there > something faster than a loop? My current loops takes well over 24 hours to > run. > > > m<-matrix(0,1,24) > for(i in 1:n) > { >   a<-matrix(x[i,1:4],1,4) > j=1 >        nn<-nrow(m) >        counter<-0 >        while(j<=nn) >        { >          if(a>m[j,1] && a>m[j,2] && a>m[j,4] && a          { >            m<-m[-j,] >            nn<-length(m[,1]) >            counter<-1 >          } else j<-j+1 >        } >        if(counter==1) >        { >          b<-cbind(a,x) >           m<-rbind(m,b) >        } >        if(counter==0) >        { >          if(a>min(m[,1]) || a>min(m[,3]) || a>min(m[,4]) || > a          { >            b<-cbind(a,x) >             m<-rbind(m,b) >          } >       } > } > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637305.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Speeding up a loop

 Any chance I could ask for an idiots guide for function to.keep(x). I understand how to use it but not what some of the lines are doing. Comments would be extremely helpful.
Open this post in threaded view
|

## Re: Speeding up a loop

Open this post in threaded view
|

## Re: Speeding up a loop

 1.15           60 0.553555415         0.574892872 1.15   60 0.563183983         0.564029359 Shouldn't the function row out the second one, since it it higher in position 3 and lower in position 4 i.e. it should not all be yes?
Open this post in threaded view
|

## Re: Speeding up a loop

 Hello, I think this is a boundary issue. In your op you've said "less" not "less than or equal to". Try using "<=" and ">=" to see what happens, I bet it solves it. Rui Barradas Em 23-07-2012 14:43, wwreith escreveu: > 1.15           60 0.553555415         0.574892872 > 1.15   60 0.563183983         0.564029359 > > Shouldn't the function row out the second one, since it it higher in > position 3 and lower in position 4 i.e. it should not all be yes? > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637438.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|