R-alpha: select.frame

Peter Dalgaard BSA p.dalgaard@kubism.ku.dk
15 Apr 1997 00:59:23 +0200


Here's the select.frame() function I babbled about before. Suggestions
about coding style, etc., are welcome, I feel a bit green at this.

select.frame<-
function (dfr, ...) 
{
        subst.exp <- function(e) {
                for (i in 2:length(e)) {
                        ei <- e[[i]]
                        if (is.call(ei)) 
                                e[[i]] <- subst.exp(ei)
                        else {
                                n <- match(as.character(ei), nm)
                                if (!is.na(n)) 
                                 e[[i]] <- n
                        }
                }
                e
        }
        nm <- names(dfr)
        e <- as.call(c(as.name("c"), expression(...)))
        dfr[, eval(subst.exp(e))]
}


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-