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

  • Home
  • SEARCH
  • 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 7817057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:06:08+00:00 2026-06-02T06:06:08+00:00

Very new, so let me know if this is asking too much. I am

  • 0

Very new, so let me know if this is asking too much.
I am trying to sub set panel data, in R, into two different categories; one that has complete information for variables and one that has incomplete information for variables. My data looks like this:

Person     Year Income Age Sex
    1      2003  1500   15  1
    1      2004  1700   16  1
    1      2005  2000   17  1
    2      2003  1400   25  0
    2      2004  1900   26  0
    2      2005  2000   27  0

What I need to do is go through each column ( not columns 1 and 2 ) and if the data is full for the variable ( variables are defined by the id in the first column and then the column name, in the picture above an example is person1Income) return that to a data set. Else put it in a different data set. Here is my meta code and an example of what it should do given the above data. Note: I call variables by their id name then the column name, for instance the variable person1Income would be the first three rows in column three.

for(each variable in all columns except 1 and 2 in data set) if (variable = FULL) { return to data set "completes" }
else {put in data set "incompletes"}
completes = person1Income, person2Income, person1Age, person2Age, person1Sex, person2 sex
incompletes = {empty because the above info is full}

I understand if someone can’t answer this question completely, but any help is appreciated. Also if my goal is not clear, let me know and I will try to clarify.

tl;dr I can’t yet explain it in one sentence so…sorry.

Edit: visualization of what I mean by complete and incomplete variables. screenshot

  • 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-06-02T06:06:11+00:00Added an answer on June 2, 2026 at 6:06 am

    Using your picture, here’s a stab at what you want. It may be long-winded and others may have a more elegant way of doing it, but it gets the job done:

    library("reshape2")
    
    con <- textConnection("Person Year Income Age Sex
      1      2003  1500   15  1
      1      2004  1700   16  1
      1      2005  2000   17  1
      2      2003  1400   25  0
      2      2004  1900   NA  0
      2      2005  2000   27  0
      3      2003  NA   25  0
      3      2004  1900   NA  0
      3      2005  2000   27  0")
    pnls <- read.table(con, header=TRUE)
    
    # reformat table for easier processing
    pnls2 <- melt(pnls, id=c("Person"))
    # and select those rows that relate to values
    # of income and age
    pnls2 <- subset(pnls2,
                  variable == "Income" | variable == "Age")
    
    # create column of names in desired format (e.g Person1Age etc)
    pnls2$name <- paste("Person", pnls2$Person, pnls2$variable, sep="")
    
    # Collect full set of unique names
    name.set <- unique(pnls2$name)
    # find the incomplete set
    incomplete <- unique( pnls2$name[ is.na(pnls2$value) ]) 
    # then find the complement of the incomplete set
    complete <- setdiff(name.set, incomplete) 
    
    # These two now contain list of complete and incomplete variables
    complete
    incomplete
    

    If you are not familiar with melting and the reshape2 package, you may want to run it line by line, and examine the value of pnls2 at different stages to see how this works.

    EDIT: adding code to compile the values as requested by @bstockton. I am sure there is a much more appropriate R idiom to do this, but once again, in the absence of better answers: this works

    # use these lists of complete and incomplete variable names
    # as keys to collect lists of values for each variable name
    compile <- function(keys) {
        holder = list()
        for (n in keys) {
            holder[[ n ]] <- subset(pnls2, pnls2$name == n)[,3]
        }
        return( as.data.frame(holder) )
    }
    
    complete.recs <- compile(complete)
    incomplete.recs <- compile(incomplete)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start by saying I'm very new to Java and to this site.
I'm very new at testing so please let me know if I am just
This is somewhat a two-part question (please let me know if they should be
I'm using MVVM in a WPF app. I'm very new to both. Let me
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new mobile developer here... I am trying to retrieve a list of tweets
Im very new to all coding including jquery. I though this would have been
I'm very new to this, so go easy on me. From my understanding, JAXB
Let me start off by saying, I'm not new to programming but am very
I am very new to Android development. I have this code: Button btnLaunch; btnLaunch=(Button)findViewById(R.id.btnLaunch);

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.