Tip:
Highlight text to annotate it
X
To get acquainted with R, let's do some basic
calculations.
We can add numbers, multiply numbers, and we can invoke
built-in functions to do more complex calculations.
So R is good at calculations, but we don't want to type in
all of our data.
Instead, we'll often store our data into R objects.
In a later video, we'll load in larger data objects, but
for now let's create some simple R objects.
Let's save the value 4 to an object called x.
Usually we use a less than symbol followed by a dash to
communicate that we want to save something like a number
into an R object.
Now we can use x to do some basic calculations.
For example, x times x, or we can calculate the
square root of x.
Note that sometimes people might call x a variable, so
think of the terms "object" and "variable" as meaning the
same thing in R. The names of R objects can include letters,
numbers, underscores, and periods.
However, the name should always start with a letter,
usually one that is lowercase.
If you'll be sharing your code with others, check with your
group to see if there's a style guide that you should
follow for your R code.
One last tip--
if you want to review an earlier command you made,
click the command line on the R console and then hit the up
arrow on your keyboard.
When you do this, you will be able to see earlier commands
you have run, and if you desire, you can re-run them.
In the next video, we'll create and work with the
vectors in R.