0
votes

I am a beginner to R and I would really appreciate all help. I have some data, which I cleaned, removed duplicates,etc. Now, I have this data in a csv file, my main issue is that I am not able to convert it into transactions. I am only able to convert them into lists, but not as transactions.

Please let me know how I can change this data to

This data (like as transactions)

Please help, TIA!!

1
Look at the manual page of read.transactions using ? read.transactions. There is an example that does exactly what you want.Michael Hahsler

1 Answers

1
votes

To convert csv file into transaction file use this code. suppose tfile is the name of csv file

colnames = names(tfile)

bas_str = ""

for(row in 1:nrow(x)){ 


    if(row !=1){                          
            bas_str = paste0( bas_str, "\n")}
    bas_str = paste0(bas_str,row,",")     
    for(col in 2:length(colnames)){      
           if(col != 2){                       
                  bas_str = paste0(bas_str,",")}
    bas_str = paste0(bas_str,colnames[col],"=",tfile[row,col])}}