Created
March 11, 2012 01:35
-
-
Save stevendanna/2014462 to your computer and use it in GitHub Desktop.
summarize: A script to generate summarize statistics from input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/Rscript | |
# | |
# Quickly generate some basic descriptive | |
# statistics from stdin | |
# | |
library('optparse', quietly=TRUE) | |
option_list <- list(make_option(c("-H", "--header"), action="store_true", default=FALSE, | |
help="Use first line of input as headers."), | |
make_option(c("-r", "--rownames"), action="store", default=NULL, | |
help="Column to use as row names."), | |
make_option(c("-s", "--sep"), action="store", default="", | |
help="Column seperator. Defaults to white space")) | |
parser <- OptionParser(usage = "%prog [OPTIONS] [FILE]", option_list=option_list) | |
arguments <- parse_args(parser, positional_arguments=TRUE) | |
opts <- arguments$options | |
args <- arguments$args | |
input_file <- if (is.na(args[1])) { | |
file('stdin') | |
} else { | |
args[1] | |
} | |
input <- read.table(input_file, header=opts$header, sep=opts$sep, row.names=opts$rownames) | |
summary(input) | |
write("\nCovariance Matrix:", stdout()) | |
var(input) | |
write("\nColumn Sums:", stdout()) | |
colSums(input) | |
write("\nNumber of Rows:", stdout()) | |
nrow(input) | |
write("\nFirst 6 Rows:", stdout()) | |
head(input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment