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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:54:12+00:00 2026-06-08T07:54:12+00:00

I have data from a survey. It comes from a question that looks like

  • 0

I have data from a survey. It comes from a question that looks like this:

Did you do any of the following activities during your PhD

                             Yes, paid by my school. Yes, paid by me.  No. 

Attended an internationl conference?
Bought textbooks? 

The data is automatically saved in a spreadsheet in this way:

id conf.1 conf.2 conf.3 text.1 text.2 text.3

1    1                              1
2           1               1
3                   1       1
4                   1                    1
5               

This means participant 1 attended a conference paid by her university; particiapnt 2 attended the conference paid by him, and participant 3 didn’t go.

I want to merge conf.1, conf.2 and conf.3 and text.1, text.2 and text.3 in single variables

id new.conf new.text

1   1        2
2   2        1
3   3        1
4   3        3

where the number now respresents the categories of the survey question

Thanks for 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-06-08T07:54:15+00:00Added an answer on June 8, 2026 at 7:54 am

    You don’t state whether or not each set of questions can have multiple answers. If so, this approach may not work for you. If that’s the case, I suggest making your question more reproducible before moving forward. With that caveat out of the way, give this a whirl:

    library(reshape2)
    #recreate your data
    dat <- data.frame(id = 1:5,
                      conf.1 = c(1,rep(NA,4)),
                      conf.2 = c(NA,1, rep(NA,3)),
                      conf.3 = c(NA,NA,1,1, NA),
                      text.1 = c(NA,1,1,NA,NA),
                      text.2 = c(1, rep(NA,4)),
                      text.3 = c(rep(NA,3),1, NA))
    
    #melt into long format
    dat.m <- melt(dat, id.vars = "id")
    #Split on the "."
    dat.m[, c("variable", "val")] <- with(dat.m, colsplit(variable, "\\.", c("variable", "val")))
    #Subset out only the complete cases
    dat.m <- dat.m[complete.cases(dat.m),]
    #Cast back into wide format
    dcast(id ~ variable, value.var = "val", data = dat.m)
    #-----
      id conf text
    1  1    1    2
    2  2    2    1
    3  3    3    1
    4  4    3    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data collected from a survey. One factor variable is like this: Column1
I have data from two different sources that I need to combine. Some data
I have some data from log files and would like to group entries by
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
I have data from a table in a database (string) that contain text and
I have data from a CSV file that's already loaded into memory. So I
I'm trying to get hold of data from a NSXMLParser I have the following
We have a web application that saves survey data in XML format, rather than
I have developed an online survey that stores my data in a Microsoft SQL
I have data in an Excel spreadsheet with values like this: 0.69491375 0.31220394 The

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.