samedi 30 mars 2019

R - If statement function to set value of new column

I have 2 columns pos and neg, each with a integer value.

I would like to create a new column score, with each element of this column given a value of:

  • 1 if pos > neg
  • 0 if pos = neg
  • -1 if pos < neg

What would be the best way to do this? I am new to creating functions in R, so any help or direction is appreciated.

Aucun commentaire:

Enregistrer un commentaire