I'd like to create a conditional new_column from 2 existing columns. Existing columns must contain either 0 or 1. I had some ideas about loops already which are not working.
In a nutshell, if column1
has a number equal to 1 and column2
has a number equal to 0, then new_column
will be 0 and only equal to 1 if both columns are 1).
desired output
Column1 column2 new_column
1 0 0
0 0 0
1 1 1
I am a newbie to R.
I have already tried several topics such as:
- creating a new column from an existing column using R
- Using do loops in R to create new variables
- R Data.Table create a variable with a condition
I want to thanks the R community for their help