We're almost done with Part 1 of the course! We've covered quite a lot of information here, so let's do a quick recap.
R knows how to work with number and text values. With numeric values, you can perform various calculations: addition (
5+4), subtraction (
5-1), multiplication (
15*4), division (
5/4). Text values are surrounded with single or double quotes ("Mary" or 'Mary').
The results of calculations can be stored in a variable:
weight <- 75
Variables can be used in further calculations, e.g.:
weight + 10
You can compare values saved in variables with other values using comparison operators (e.g.
height < 160). Such comparisons return a single logical value:
R has many built-in functions that perform all kinds of predefined calculations. A function is called by its name. In parentheses, you pass in the arguments to the function:
There are functions that work with number values (like
round) and those that work with text values (
substr). You can get more information about a function by using the help operator followed by the function name, like so:
You can also write comments in R. A comment is anything that follows
# on a single line. These serve no other purpose than to document your code. That's about it! It's time to test what you've learned. Ready?