Search code examples
rformattingoutputline

format R output to get each result in separate line and with alphabet as line identifiers


When I try to get unique values, following is the result I got.

unique( big1.csv[grepl("c1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks))
                           &grepl("back", tolower(big1.csv$Remarks))
                           , ]$New_Remarks)

[1] "c1 noted to back and arms, dose repeated"               "c1 noted to back of arms and flanks, dose repeated"    
 [3] "c1 noted to arms and back, dose repeated"               "c1 noted to back and upper arms, dose repeated"        
 [5] "c1 noted to back of arms, dose repeated"                "c1 noted to back and chest, dose repeated"             

How can I get each result in a separate line with alphabets instead of line numbers like this? Or roman numbers?

 [a] "c1 noted to back and arms, dose repeated" 
 [b] "c1 noted to back of arms and flanks, dose repeated"    
 [c] "c1 noted to arms and back, dose repeated"   
 [d] "c1 noted to back and upper arms, dose repeated"        
 [e] "c1 noted to back of arms, dose repeated" 
 [f] "c1 noted to back and chest, dose repeated" 

Solution

  • Probably you could combine your unique.strings with a custom made ID in a data frame.

    unique.strings <- unique( big1.csv[grepl("e1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks))
                           &grepl("back", tolower(big1.csv$Remarks))
                           , ]$New_Remarks)
    df <- data.frame(ID = paste0("[", letters[1:length(unique.strings)], "]"), unique.strings)