dimanche 29 mars 2020

How would I create an if statement for strings based on multiple conditions in R?

So I want to create a new column in my dataset that would be "1" if True and "0" if false.

My data is setup similar to this:

v1 v2 v3
a  b  c
b  b  c
d  b  c

Let's say that I want my if statement to be setup to where if v1 equals a, b, or c, then the new column would be 1. Under this new condition, I would want my new dataset to look like this.

v1 v2 v3 v4
a  b  c  1
b  b  c  1
d  b  c  0

How would I go about setting this up? Hopefully I made sense explaining this, I tried to simplify as much as possible.

Aucun commentaire:

Enregistrer un commentaire