Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:02+00:00 2026-05-22T14:23:02+00:00

I have several files of data that look like this: X code year month

  • 0

I have several files of data that look like this:

X code year month day pp  
1 4515 1953     6   1  0  
2 4515 1953     6   2  0  
3 4515 1953     6   3  0  
4 4515 1953     6   4  0  
5 4515 1953     6   5  3.5

Sometimes there is data missing, but I don’t have NAs, the rows simply don’t exist. I need to create NAs when the data is missing. I though I could start by identifying when that occurs by converting it to a zoo object and check for strict regularity (I never used zoo before), I used the following code:

z.date<-paste(CET$year, CET$month, CET$day, sep="/")
z <- read.zoo(CET,  order.by= z.date )
reg<-is.regular(z, strict = TRUE)

But the answer is always true!

Can anyone tell me why is not working? Or even better, tell me a way to create NAs when the data is missing (with or without zoo package)?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:23:03+00:00Added an answer on May 22, 2026 at 2:23 pm

    The seq function has some interesting features that you can use to easily generate a complete sequence of dates. For example, the following code can be used to generate a sequence of dates starting on April 25:

    Edit: This feature is documented in ?seq.Date

    start = as.Date("2011/04/25")
    full <- seq(start, by='1 day', length=15)
    full
    
     [1] "2011-04-25" "2011-04-26" "2011-04-27" "2011-04-28" "2011-04-29"
     [6] "2011-04-30" "2011-05-01" "2011-05-02" "2011-05-03" "2011-05-04"
    [11] "2011-05-05" "2011-05-06" "2011-05-07" "2011-05-08" "2011-05-09"
    

    Now use the same principle to generate some data with “missing” rows, by generating the sequence for every 2nd day:

    partial <- data.frame(
        date=seq(start, by='2 day', length=6),
        value=1:6
    )
    partial
    
            date value
    1 2011-04-25     1
    2 2011-04-27     2
    3 2011-04-29     3
    4 2011-05-01     4
    5 2011-05-03     5
    6 2011-05-05     6
    

    To answer your question, one can use vector subscripting or the match function to create a dataset with NAs:

    with(partial, value[match(full, date)])
     [1]  1 NA  2 NA  3 NA  4 NA  5 NA  6 NA NA NA NA
    

    To combine this result with the original full data:

    data.frame(Date=full, value=with(partial, value[match(full, date)]))
             Date value
    1  2011-04-25     1
    2  2011-04-26    NA
    3  2011-04-27     2
    4  2011-04-28    NA
    5  2011-04-29     3
    6  2011-04-30    NA
    7  2011-05-01     4
    8  2011-05-02    NA
    9  2011-05-03     5
    10 2011-05-04    NA
    11 2011-05-05     6
    12 2011-05-06    NA
    13 2011-05-07    NA
    14 2011-05-08    NA
    15 2011-05-09    NA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data files from a legacy system that I would like to
I have several fairly large XML files that represent data exported from a system
I'm trying to merge several files with libxml2 SAX. Original files look like this:
I have several .csv files with similar filenames except a numeric month (i.e. 03_data.csv,
I have several existing XML schema files with a defined data model. I would
I have several files that are in several different languages. I thought they were
I have several files containing this line Release: X I want to increment X
I'm writing multilingual website. I have several files on server like: /index.php /files.php /funny.php
I have several batch files that I call from a parent batch file. I
I have several files with code testing code (which uses a unittest class). Later

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.