Basic R Syntax
Explore the basics of R syntax by learning about assignment operators, how to output data, write comments, and perform arithmetic operations. This lesson helps you understand the core structure of R scripts, enabling you to write clear and effective data science code in R with confidence.
We'll cover the following...
R has six main components: base-R, the R console, CRAN, an IDE, scripts, and the working directory. This lesson will focus on base-R, the R console, scripts, and the IDE. We won’t be using any extensions from CRAN yet, and we won’t be setting up a working directory—these will be discussed in more detail in the upcoming lessons.
Code structure
Any R script in this course will follow the same basic structure:
- Take in some data
- Manipulate it and perform some statistical operations
- Output the results in one form or another
Structuring our code with these three major sections is the best practice that delineates data science code in R. Over time, we’ll add complications and sub-components, but this will always be the primary underlying structure.
Our first example
That being said, we’ll start with a typical “Hello, world!” example and build toward a data-driven model throughout this lesson.
Value assignment
Line 1 is an assignment operation. It puts the value “Hello, world!” into the variable VAR_InputText. Notice that there are no declared data types, as there would be in some other programming languages. In R, it’s not necessary to specify what kind of data a variable will contain.
Also notice the operator <-, which is one ...