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 6865885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:06:35+00:00 2026-05-27T03:06:35+00:00

I have a data set that looks like this: ByYear <- data.frame( V1 =

  • 0

I have a data set that looks like this:

ByYear <- data.frame( V1 = c(2005,2006,2007,2008,2005,2006,2008,2006,2007,2005,2006,2007,2008),
                      V2 = c(0.5,0.2,1,1.6,2,5,8,4,3,6,8,6,5), 
                      V3 = c('A','A','A','A','B','B','B','C','C','D','D','D','D'))

Which gives me

> ByYear
   V1   V2  V3
1  2005 0.5 A
2  2006 0.2 A
3  2007 1.0 A
4  2008 1.6 A
5  2005 2.0 B
6  2006 5.0 B
7  2008 8.0 B
8  2006 4.0 C
9  2007 3.0 C
10 2005 6.0 D
11 2006 8.0 D
12 2007 6.0 D
13 2008 5.0 D

Some of the years are missing from V1. This is due to an error in how the data were entered. I know this is a touchy subject, but I know for a fact that in this case a missing year in V1 means the value in V2 should be 0.

Is there a way I can create a new data set that adds a row with a zero value to any missing year like so:

> ByYear
  V1   V2  V3
  2005 0.5 A
  2006 0.2 A
  2007 1.0 A
  2008 1.6 A
  2005 2.0 B
  2006 5.0 B
  2007 0.0 B
  2008 8.0 B
  2005 0.0 C
  2006 4.0 C
  2007 3.0 C
  2008 0.0 C
  2005 6.0 D
  2006 0.0 D
  2007 6.0 D
  2008 5.0 D

Thanks for everyone for all your help!

  • 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-27T03:06:36+00:00Added an answer on May 27, 2026 at 3:06 am

    Use table to find the missing year/group combinations.

    Frequencies <- with(ByYear, as.data.frame(table(V1, V3)))
    MissingValues <- subset(Frequencies, Freq == 0, c(V1, V3))
    

    Set the value of V2 to be 0 (or NA or whatver you want), then append this to your original dataset.

    MissingValues$V2 <- 0
    rbind(ByYear, MissingValues)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that looks like this: 000 100 200 300 010
I have a set of data that looks like this when using print_r($var) :
So I have a large set of data that looks like this [('ART', [100,
I have a SQL table set that looks like this create table foo (
I have data that always looks something like this: alt text http://michaelfogleman.com/static/images/chart.png I need
I have a data grid that looks like this <tk:DataGrid ItemsSource={Binding Parents} AutoGenerateColumns=False> <tk:DataGrid.Columns>
I have an Oracle table with data that looks like this: ID BATCH STATUS
I have a data set that looks like the below (the input). IR# CR#
I have some nicely-structured data that looks like this: CREATE TABLE SourceBodyPartColors ( person_ID
I have data that looks like this: > head(data) date price volume 1 2011-06-26

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.