All complex analyses comprise sequences of multiple simple operations. To get acquainted with R and "build trust," please read about these operations you can implement in the R (RStudio) console and immediately see the results. Run the codes on your computer. Do you get the same outputs? Try changing some of the code to see how the outputs will change. You should be able to guess what kind of output you can get from any of these simple operations.
Comparing Things
We can also do comparisons in R:
1 == 1 # equality (note two equals signs, read as "is equal to")
Output |
---|
|
1 != 2 # inequality (read as "is not equal to")
Output |
---|
|
1 < 2 # less than
Output |
---|
|
1 <= 1 # less than or equal to
Output |
---|
|
1 > 0 # greater than
Output |
---|
|
1 >= -9 # greater than or equal to
Output |
---|
|
Tip: Comparing Numbers
A word of warning about comparing numbers: you should never use
==
to compare two numbers unless they are integers (a data type which can specifically represent only whole numbers).Computers may only represent decimal numbers with a certain degree of precision, so two numbers which look the same when printed out by R, may actually have different underlying representations and therefore be different by a small margin of error (called Machine numeric tolerance).
Instead you should use the
all.equal
function.