title: R Categorising data using multiple If() statements
body: <p>I have created a table with football players and specific positions. I would now like to also categorise each player into their general positions (GPosition) i.e. Goalkeeper, Defender, Midfielder and Forward. Sorry if these seems rudimentary, but I am very new to R</p>
  
  <p>Part of my Data is below:</p>
  
  <pre><code>            Player      Position  GPosition
  1  Thibaut Courtois       Keeper  Goalkeeper
  2   Willy Caballero       Keeper  Goalkeeper
  9           Eduardo       Keeper  Goalkeeper
  17      Matej Delac       Keeper  Goalkeeper
  19       David Luiz  Centre-Back  Goalkeeper
  22  Antonio Rüdiger  Centre-Back  Goalkeeper
  </code></pre>
  
  <p>I have tried using If() or Which() statements but have run into a few issues. When I run my code all GPositions run as GoalKeeper rather than other classifications. I am also unsure if using th "==" is the correct code to be using for this.</p>
  
  <p>Part of my code:</p>
  
  <pre><code>PlayerPositions$GPosition &lt;- if(PlayerPositions$Position == "Keeper") {
    PlayerPositions$GPosition &lt;- "Goalkeeper"
  } else if (PlayerPositions$Position == "Centre-Back"){
    PlayerPositions$GPosition &lt;- "Defender"
  } else if (PlayerPositions$Position == "Left-Back"){
    PlayerPositions$GPosition &lt;- "Defender"
  } else if (PlayerPositions$Position == "Right-Back"){
    PlayerPositions$GPosition &lt;- "Defender"
  </code></pre>
  
  <p>And so on.... until last line:</p>
  
  <pre><code>} else if (PlayerPositions$Position == "Right Wing") {
    PlayerPositions$GPosition &lt;- "Forward"
  }
  </code></pre>