[R] assigning creating missing rows and values
David Winsemius
dwinsemius at comcast.net
Thu May 12 22:43:02 CEST 2011
On May 12, 2011, at 4:33 PM, Schatzi wrote:
> I have a dataset where I have missing times (11:00 and 16:00). I
> would like
> the outputs to include the missing time so that the final time
> vector looks
> like "realt" and has the previous time's value. Ex. If meas at time
> 15:30 is
> 0.45, then the meas for time 16:00 will also be 0.45.
> meas are the measurements and times are the times at which they were
> taken.
>
> meas<-runif(18)
> times<-
> c
> ("08
> :
> 30
> ","09
> :
> 00
> ","09
> :
> 30
> ","10
> :
> 00
> ","10
> :30","11:30","12:00","12:30","13:00","13:30","14:00","14:30","15:00",
> "15:30" ,"16:30","17:00","17:30","18:00")
> output<-data.frame(meas,times)
> realt<-
> c
> ("08
> :
> 30
> ","09
> :
> 00
> ","09
> :
> 30
> ","10
> :
> 00
> ","10
> :
> 30
> ","11
> :
> 00
> ","11
> :
> 30
> ","12
> :
> 00
> ","12
> :
> 30
> ","13
> :
> 00
> ","13
> :
> 30
> ","14
> :00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00")
Package 'zoo' has an 'na.locf' function which I believe stands for
"NA's last observation carried forward". So make a regular set of
times, merge and "carry forward". I'm pretty sure you can find may
examples in the Archive. Gabor is very good about spotting places
where his many contributions can be successfully deployed.
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list