Skip to content
Prev 77546 / 398502 Next

Neat way of using R for pivoting?

Actually, it's even better to write functions for repetitive tasks.
This is one of the things Martin talked about at useR! 2004:
http://www.ci.tuwien.ac.at/Conferences/useR-2004/Keynotes/Maechler.pdf

For Keith's problem, here's one possibility (using plotCI() from gplots):

myErrorBarPlot <- function(SNR, timeError, ...) {
    stopifnot(require(gplots))
    m <- aggregate(timeError, list(SNR), mean)
    d <- aggregate(timeError, list(SNR), sd)
    dat <- cbind(m, d[, 2])
    names(dat) <- c("SNR", "mean", "sd")
    dat$SNR <- as.numeric(as.character(dat$SNR))
    with(dat, plotCI(SNR, mean, uiw=3*sd, ...))
    invisible(dat)
}

vn <- read.table("clipboard", header=TRUE)

myErrorBarPlot(vn$SNR, vn$timeError)

Andy