[R] Creating data.frames dynamically

From: Worik R <worikr_at_gmail.com>
Date: Sun, 11 May 2008 15:12:52 +1200


I have time series data in named vectors. They are all the same length for the same dates.

The dates are in a separate vector.

I want to create a vector of numeric data for every named series, associated with the dates in a data.frame.

So if...

Names <- c("a", "b", "c")

d <- data.frame(dates=Dates, a=vector(mode="numeric", length=length(Dates), b=vector(mode="numeric", length=length(Dates), c=vector(mode="numeric", length=length(Dates))

Then I copy the processed data into d

for(i in SomeVectorOfFactors){

    for(N in Names){

        d[[N]][i] <- FunctionCallOfSomeSort(i)     }
}

I want to create the data.frame, d, in the same style I access it.

d <- data.frame(dates=Dates, [[Names]]=vectors(.....))

Then it is much simpler to add new columns.

Worik                                                                 ST

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 11 May 2008 - 03:18:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 12 May 2008 - 06:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive