title: Replace values in a .txt value
body: <p>I have a dataset that looks like this:</p>
  
  <pre><code>B1,F1,D1,B0 B0  D1  F1  B1  B1,A1,E1    C#2 B1,G1,E1    B1,G1,E1    C#2,A1,E1   B1,G1,E1    B1  E2  B1,F1,D1    B1,D1,B0    B1,D1,B0    A1  F1  D1  G1,E1,B0    G1  G1  G1  E1  G1
  B-1 A-1 G-1 G-1 F-1 E-1 B-1 B-1 B-1 E-1
  </code></pre>
  
  <p>What I would like to now is to read in the values and then replace specific values.</p>
  
  <p>So the pseudo code is:</p>
  
  <pre><code>#Read in data
  #For line in data:
   #Split words
    #if word contains value from list (fe C,D)
     #Replace it by X
  </code></pre>
  
  <p>So if my list is </p>
  
  <pre><code>list_replace = c("B", "F")
  </code></pre>
  
  <p>My expected output is:</p>
  
  <pre><code>X1,F1,D1,X0 X0  D1  X1  X1  X1,A1,E1    C#2 X1,G1,E1    X1,G1,E1    
  C#2,A1,E1   X1,G1,E1    X1  E2  X1,X1,D1    B1,D1,B0    X1,D1,X0    A1  X1  
  D1  G1,E1,X0    G1  G1  G1  E1  G1
  
  X-1 A-1 G-1 G-1 X-1 E-1 X-1 X-1 X-1 E-1
  </code></pre>
  
  <p>I created the following code:</p>
  
  <pre><code>#Read in datea
  data &lt;-read.table("sample.txt", header = FALSE)
  for i in 1:nrow(data){
    words = strsplit(data[i]
    for word 1:length(words){
     #Replace values
   }
  }
  </code></pre>
  
  <p>However now I only gets the first value of my to_be_replaced list. Any suggestion on how i can replace everything... And the preferably edit it right away in the .txt file.</p>