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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:23:54+00:00 2026-06-04T04:23:54+00:00

I have data collected from a survey. One factor variable is like this: Column1

  • 0

I have data collected from a survey. One factor variable is like this:

Column1  Column2  Column3  Column4  Column5
A        B        C
B        C
A        B        C        D        E
A        C        E
C        E
B        D        E

In other words, classes are spread in many different variables. I want to create one binary variable (1 or 0) for each class (A, B, C, D, E). However it’s not clear to me how to do it. How can I do it?

EDIT

The output would be something like this:

A      B      C      D      E
1      1      1      0      0
0      1      1      0      0
1      1      1      1      1
1      0      1      0      1
0      0      1      0      1
0      1      0      1      1
  • 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-04T04:23:55+00:00Added an answer on June 4, 2026 at 4:23 am
    > data <- data.frame(Column1=c("A","B","A"),Column2=c("B","A","A"))
    > data
      Column1 Column2
    1       A       B
    2       B       A
    3       A       A
    > f <- unique(unlist(data))
    > tb <- data.frame(sapply(f, function(x) (rowSums(data == as.character(x)) != 0)*1))
    > names(tb) <- f
    > tb
      A B
    1 1 1
    2 1 1
    3 1 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that collects data from users and I want to check
I have data naively collected from package dependency lists. Depends: foo bar baz >=
I have a map. On this map I want to show live data collected
I have a database table that contains collection data for product collected from a
We have a data collection system that collects measurements from environmental sensors that measure
I have the following situation: I have an application that collects some data from
I have data in a python dictionary that I'd like to store in a
I'm using Highcharts to represent groups of time series. So, data points collected from
I have a big panel of data from Compustat. To it I am adding
First of all, I got this huge xml file that represents data collected by

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.