Subject: [R] stack operations on vectors
From: Aidan Dysart (adysart@nonlineardynamics.com)
Date: Fri 21 Apr 2000 - 03:08:41 EST
Message-ID: <Pine.LNX.4.10.10004201303370.2765-100000@ebony.nonlineardynamics.com>
It would be nie to have some basic stack operations for simple vectors and
lists. ie:
> a <- c(1,2,3,4,5)
> b <- pop(a)
> a
[1] 1 2 3 4
>b
[1] 5
> push(b, 6)
> b
[1] 5 6
notice how pop and push modify the original vector and not local copy
inside the functions environment. Is there any way to do this? I tried
this:
push <- function(vec,val) {
vec <<- c(vec,val)
}
pop <- function(vec) {
l <- length(vec)
val <- vec[l]
vec <<- vec[1:(l-1)]
val
}
but those only create the object 'vec' in the global environment. is there
a way to pass an object by reference?
It seems like the only way to do this would be to have it call an
internal function.
PS. please include me in the reply, and I am only on the R-Help digest.
thanks.
-- Aidan Dysart | adysart@nonlineardynamics.com | www.nonlineardynamics.com-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:16 EST