# Re: [R] Creating data.frames dynamically

From: Yasir Kaheil <kaheil_at_gmail.com>
Date: Sun, 11 May 2008 21:15:41 -0700 (PDT)

Hi Worik:

Is this what you want?

> Names <- letters[1:5];
> Dates<- 1:20;
> d<- data.frame(dates=Dates, a = vector(mode="numeric",
> length=length(Dates)));
> for(i in 2:5){d[,paste(sep="",Names[i])]<-with(d,a)}; d

dates a b c d e

```1      1 0 0 0 0 0
2      2 0 0 0 0 0
3      3 0 0 0 0 0
4      4 0 0 0 0 0
5      5 0 0 0 0 0
6      6 0 0 0 0 0
7      7 0 0 0 0 0
8      8 0 0 0 0 0
9      9 0 0 0 0 0
```

10 10 0 0 0 0 0
11 11 0 0 0 0 0
12 12 0 0 0 0 0
13 13 0 0 0 0 0
14 14 0 0 0 0 0
15 15 0 0 0 0 0
16 16 0 0 0 0 0
17 17 0 0 0 0 0
18 18 0 0 0 0 0
19 19 0 0 0 0 0
20 20 0 0 0 0 0

thanks
y

Worik R wrote:
>
> 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
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

Yasir H. Kaheil
Catchment Research Facility
The University of Western Ontario
```--
View this message in context: http://www.nabble.com/Creating-data.frames-dynamically-tp17169662p17181259.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help