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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:16:15+00:00 2026-06-18T19:16:15+00:00

I currently have a table set up in a basket format so that an

  • 0

I currently have a table set up in a basket format so that an irregular amount of data is associated with each row of the table. Such as:

01,item1,item2,item3
02,item1,item2,
03,item1,item2,item3,item4
04,item1

However, I need to change it to a normalized transactional format with only one item on each row. Such as:

01,item1
01,item2
01,item3
02,item1
02,item2
03,item1

…and so on. Is there an easy automated or programmatic way to do this? The data is currently in a MySQL database that I can export in a variety of file types, and I also have access to RStudio, and Microsoft Excel to try to do this. All the transactional resources I could find for RStudio assume that the data was already in the second format, which is what I’m trying to get to.

  • 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-18T19:16:17+00:00Added an answer on June 18, 2026 at 7:16 pm

    I am assuming I understand the way your data set will look once you read it into R, i.e., it will be a rectangular data frame where NA’s are filled in to make the rows the same length. So this should solve the problem:

    #Create your dataset (this step is not for you)
    row1 = c("01","item1","item2","item3",NA)
    row2 = c("02","item1","item2",NA,NA)
    row3 = c("03","item1","item2","item3","item4")
    row4 = c("04","item1",NA,NA,NA)
    
    Data = rbind(row1,row2,row3,row4)
    
    #Now do the reconstruction (this step is for you)
    col1 = NULL
    col2 = NULL
    
    for(i in 1:nrow(Data)){
        col1 = c(col1,rep(Data[i],ncol(Data)-1))
        col2 = c(col2,Data[i,-1])
    }
    
    NewData = cbind(col1,col2)[!is.na(col2),]
    

    So, what you get is the following

    > Data
         [,1] [,2]    [,3]    [,4]    [,5]   
    row1 "01" "item1" "item2" "item3" NA     
    row2 "02" "item1" "item2" NA      NA     
    row3 "03" "item1" "item2" "item3" "item4"
    row4 "04" "item1" NA      NA      NA     
    > 
    > NewData
          col1 col2   
     [1,] "01" "item1"
     [2,] "01" "item2"
     [3,] "01" "item3"
     [4,] "02" "item1"
     [5,] "02" "item2"
     [6,] "03" "item1"
     [7,] "03" "item2"
     [8,] "03" "item3"
     [9,] "03" "item4"
    [10,] "04" "item1"
    

    So hopefully that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jQuery draggable set up and working ok on a table row. Currently
I have a table set up that currently has no primary key. All I
I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have a table with an id column that is being autoincremented and
I currently have a UISegmentedControl set to add/remove table view cells when its value
I currently have a table that has a width of 94%, and the following
I currently have a table that is 17 columns wide and has 30 records.
Currently I have a table ComponentAnalysis and a table HistoryOfUse that I am trying
I currently have a gridview that is set up and working properly but I
We have a table and a set of procedures that are used for generating

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.