Skip to content

R-alpha: select.frame

1 message · Peter Dalgaard

#
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))]
}