ifelse statement r | Checking Conditions and Assigning Values

preview_player
Показать описание
One of the more common things you'll have to do in R is create new variables based on the values of other variables. An easy way to do this is by using the ifelse function in r. This function is straightforward, and only takes three arguements.

1 - A condition you want to test.
2 - If that condition is true, then what do you want to do?
3 - If that condition is false, then what are we doing to do?

We discuss the basic ifelse statement and nested ifelse statements for more complicated assignments. When evaluating conditions in R, however, it's important to remember there's many ways to do the same thing.

You may want to use another function, such as case_when, if you have to evaluate a lot of conditions because nesting ifelse statements can get messy.

If you want me to make a video on that, or any other topic in R, please let me know in the comments below!

Our Data: 0:30
ifelse statement: 1:29
Nested ifelse: 3:20
More nesting: 5:12
Рекомендации по теме