0

I have data with one of the column as

         Activity Description             
   --------------------------------------------- 
       Handling &  PNR Movement Charges-FCL        
       Value Added Charges                         
       Container Tracking Charges-FCL              
       Contrainer Ground Rent Charges-FCL          
       Documentation Charges FCL                   
       Insurance Charges-FCL                       
       Seal Charges                                
       Fuel Charges-FCL                            
       Container Movement and Increase Charges-FCL 
       Weighment Charges-FCL                       
       Container Movement and Increase Charges-FCL 

I need to search for string which contains "FCL" and replace the word without FCL. Ex. Insurance charges-FCL to Insurance charges i.e I dont need the string FCL.

I tried with below code,

 for (line in file_read$`Activity Description`){
 if (line == "*FCL"){
 new_column <- c(new_column,"*")

It is not working.

Is my code right or I need to change with another script of code?

Can anyone help me on this?

krishna31
  • 113
  • 1
  • 9

1 Answers1

1

Assuming that FCL would always occur at the end of your descriptions, preceded by a dash, space, or some other non alphanumeric character, then here is a safe way to do the replacement using sub:

df$`Activity Description` <- sub("[^[:alnum:]]FCL$", "", df$`Activity Description`)
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360