Hi:

# Create a sequence of consecutive dates and assign to a data frame

dates <- data.frame(day = seq(as.Date('2009-12-01'), by = 'days', length =
10))

# Let's call your data frame (not vector) 'df'; to make sure that things are
# compatible,

names(df) <- c('day', 'y')
df$day <- as.Date(df$day)

# Then,
> merge(dates, df, all.x =TRUE)
          day    y
1  2009-12-01 26.8
2  2009-12-02   NA
3  2009-12-03 27.9
4  2009-12-04 25.6
5  2009-12-05 20.8
6  2009-12-06   NA
7  2009-12-07   NA
8  2009-12-08 20.8
9  2009-12-09   NA
10 2009-12-10   NA


HTH,
Dennis

On Tue, Feb 9, 2010 at 4:30 PM, Nilza BARROS <nilzabar...@gmail.com> wrote:

> Dear all,
>
> I am trying  to identify the days absent in a vector so as to be able to
> display missing data in the  graphics in .It should be done  automatically
> since  the graphics will be generated for different periods of the year.
> I have been trying to do a function below but it did not work. I really
> appreciate any help
>
> ordados <- function(datas,var)
> {
> ind <- !datas %in% var # find the missing date in var
> miss <- datas[ind]
> mat <- matrix(NA,length(miss),length(miss)) #insert  NA in the missing date
> mat[,1]<-miss
> jundado <- rbind (mat,var)
> jundado <- jundado[order(jundado[,1]),] # sort by dates
> }
> For instance:
> If I have the vector below:
>  2009-12-01     26.8
>  2009-12-03     27.9
>  2009-12-04     25.6
> 2009-12-05     20.8
> 2009-12-08     20.8
> I will need a result like this one
>
> 2009-12-01     26.8
> 2009-12-02     NA
> 2009-12-03     27.9
>  2009-12-04     25.6
> 2009-12-05     20.8
> 2009-12-06     NA
> 2009-12-07     NA
> 2009-12-08     20.8
>
> Bye and Best Regards
> Nilza Barros
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to