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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:56:37+00:00 2026-06-13T09:56:37+00:00

I currently have data that is in the following format (note, this is 1

  • 0

I currently have data that is in the following format (note, this is 1 column, 4 row matrix):

aa|bb  
bb|cc|ee|ee  
cc  
cc|ee

and I want it displayed so that the column names are: aa, bb, cc, dd, and ee. And I want there to be 4 row such that each row counts the number of times each string was present in the matching row above.

ie)

aa bb cc dd ee  
 1  1  0  0  0  
 0  1  1  0  2  
 0  0  1  0  0   
 0  0  1  0  1 

Does anyone know how to do this in R? I would post my attempt, but it is just getting ugly and complicated. Any help would be much appreciated.

Thanks in advance.

  • 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-13T09:56:38+00:00Added an answer on June 13, 2026 at 9:56 am

    Here’s an idea:

    # (You'll use as.vector() on your matrix to get the vector x.)
    x <- c("aa|bb", "bb|cc|ee|ee", "cc", "cc|ee") 
    
    levs <- c("aa", "bb", "cc", "dd", "ee")
    ll <- strsplit(x, "\\|")
    t(sapply(ll, function(X) table(c(levs, X)))) - 1
    #      aa bb cc dd ee
    # [1,]  1  1  0  0  0
    # [2,]  0  1  1  0  2
    # [3,]  0  0  1  0  0
    # [4,]  0  0  1  0  1
    

    This may clarify (at least a bit) what that final line of code does:

    table(c(levs, c("dd", "cc", "cc", "cc"))) - 1
    # 
    # aa bb cc dd ee 
    #  0  0  3  1  0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my data stored in this format : Word1 - Word2 -
I currently have the following row in my table: course_data: user_id days <-- This
Currently I have a data source that stores dates in the format yyyymmdd, and
We have our own data streaming algorithm that include some metadata+records+fields values. Currently we
I have a database that contains data for many clients. Currently, we insert tens
In the data structures class that I am currently taking, we have been tasked
I have an app that received JSON data from the server. Currently when I
Hello I have a WinForm app that generates a ton of data. Currently I
I have the following data that basically I only need a few bits of
I currently have a conf file which exists out of the following format: [client]

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.