Larry Howe <[EMAIL PROTECTED]> wants to:

> 1. read in a 2-column data file, e.g.
> status <tab> new
> db <tab> green
> title <tab> "Most Significant Excursions"
> 2. end up with an R list such that I can write e.g.
> lst$title
> and have R return "Most Significant Excursions".

I call this "reading a hash table" (because it consists of name/value
pairs), and here's a function to do it.  Note this function allows you
to input a hash if you wish, and then override its values with the
data file.  The argument defaults assume a tab-delimited text file
with a header row, which is ignored.

read.hash <- function(file, defaults=list(),
                      header=TRUE, sep="\t", ...) {
  pl <- read.table(file, as.is=TRUE, header=header, sep=sep, ...)
  for (i in seq(pl[[1]])) defaults[[pl[[1]][i]]] <- pl[[2]][i]
  defaults
}

Also see the built-in "read.dcf", which uses a different input format,
but might suit your purpose.

-- David Brahm ([EMAIL PROTECTED])

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to