Writing R programs
Although much data analysis in R can be carried out in an interactive manner using command prompt, often for more complex tasks, one needs to write R scripts. As mentioned in the introduction, R has both the perspective of a functional and object-oriented programming language. In this section, some of the standard syntaxes of the programming in R are described.
Control structures
Control structures are meant for controlling the flow of execution of a program. The standard control structures are as follows:
if
andelse
: To test a conditionfor
: To loop over a set of statements for a fixed number of timeswhile
: To loop over a set of statements while a condition is truerepeat
: To execute an infinite loopbreak
: To break the execution ...
Get Learning Bayesian Models with R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.