[R] iteration loop shortening

Ben Bolker ben at zoo.ufl.edu
Mon Feb 11 16:10:30 CET 2002


  Set the list element to NULL.

e.g.:

a <- as.list(1:10)
for (i in 1:9) {
  j <- sample(1:length(a),size=1)
  a[[j]] <- NULL
  print(as.numeric(a))
}

On Mon, 11 Feb 2002, jimi adams wrote:

> i have a loop inside of which i am selecting elements from a list
> i am wondering if once the points are selected there is a way to remove
> the element from the list, not reduce it to zero, but actually remove
> the element from the list
>
> this is probably an easy question that i am just missing, but anywho...
>
> any assistance would be greatly appreciated
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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