If you have all the data available in one large list of lists, you can do
it with do.call("rbind", ...) like this:
> x <- list(list(name="n1",val1=1,val2=2,log=T), list(name="n2", val1=3,
val2=4, log=F))
> xx <- do.call("rbind", lapply(x, as.data.frame, stringsAsFactors=F))
> xx
name val1 val2 log
1 n1 1 2 T
2 n2 3 4 F
> sapply(xx, class)
name val1 val2 log
"character" "integer" "integer" "logical"
>
At Thursday 10:23 AM 1/20/2005, Kim Elmore wrote:
I want to build a data frame, row by row, by plugging in a list for each
row. The first element of the list is a character string, the next two are
numeric, and the last is logical. If I just naively say something like
my.df <- data.frame(Name = character(94), value1=numeric(94),
value2=numeric(94), value3=logical(94))
my.df[1,] <- my.output.list
I get a warning about what I'm putting into the first column, as that will
default to a factor. So, I set stringsAsFactors=F, and tried again. This
time, I simply get a 1 in column 1, not the string I wanted. The other
columns look fine. Obviously, I'd like to do this all at once with a
simple assignment.
What else should I try?
Kim Elmore
Kim Elmore, Ph.D.
University of Oklahoma
Cooperative Institute for Mesoscale Meteorological Studies
"All of weather is divided into three parts: Yes, No, and Maybe. The
greatest of these is Maybe" The original Latin appears to be garbled.
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|