[R] update index in

Mark Lyman mark.lyman at gmail.com
Wed Oct 25 21:15:58 CEST 2006


Kim Milferstedt <milferst <at> uiuc.edu> writes:

> 
> Hello,
> 
> I have a time series of data as a data.frame. Occasionally there is 
> one or more days missing (e.g. data available for days 2, 3, 4, 8, 9, 
> 10 --> missing days between 4 and 8). The experimental time 
> information can be found in the 2nd column of "data". I would like to 
> have a continuous time line with one time point per day. Therefore I 
> try to insert lines for the missing days that contain zeros for the 
> data categories just to fill the columns.
> 
<SNIP>
> 
> Thanks already,
> 
> Kim
> 
<SNIP>

I believe this will also do what you want:

> days<-c(1:10)[-5:-7]
> xx<-rnorm(7)
> data<-data.frame(xx,days)
> new.data<-merge(data,data.frame(days=1:10),all.y=TRUE)

It usually is not a good idea to use zeroes as placeholders for missing values.

Mark Lyman



More information about the R-help mailing list