Re: [R] assigning creating missing rows and values

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 12 May 2011 16:43:02 -0400

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

______________________________________________
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 Thu 12 May 2011 - 20:50:32 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Thu 12 May 2011 - 21:30:07 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