Entry 3778
Good R code
Submitted by Aleksandr Levchuk
on May 7, 2010 at 5:16 a.m.
Language: S. Code size: 724 bytes.
files <- list.files(pattern=".infile$") for(i in seq(along=files)) { # start for loop with numeric or character vector; numeric vector is often more flexible x <- read.table(files[i], header=TRUE, row.names=1, comment.char = "A", sep="\t") x <- data.frame(x, sum=apply(x, 1, sum), mean=apply(x, 1, mean)) # calculates sum and mean for each data frame assign(files[i], x) # generates data frame object and names it after content in variable 'i' print(files[i], quote=F) # prints loop iteration to screen to check its status write.table(x, paste(files[i], c(".out"), sep=""), quote=FALSE, sep="\t", col.names = NA) }
This snippet took 0.00 seconds to highlight.
Back to the Entry List or Home.