R TutorialLesson 13Free preview
R If...Else
This lesson is part of R · All levels
Summary
This lesson discusses the branching sequence with the constructions 'if', 'else if', and 'else' in R. Developers were also introduced to the popular built-in vector function 'ifelse()' to make conditional branching on the entire row table or vector element simultaneously.
Key points
- Conditional statement using the usual curve for the condition: 'if (kondisi) { ... }'
- The clause 'else' must be placed on the same row exactly after the curly braces closing '}' belong to the block if
- The vectorised function 'ifelse(uji, jika_true, jika_false)' facilitates the evaluation of the conditions on the data set
- The condition on the 'if' normally evaluates only one boolean value of the scalar
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.