Lecture 1: Introduction to R Flashcards
What is R?
A free statistical programming language developed by two New Zealanders.
What does R enable us to do?
- Do calculations that are basic/complex
- Undertake statistical analyses of data
- Construct graphs from data
- Write programs to carry out statistical analyses
- Keep records of everything you do in an analysis
Why use R (instead of SPSS)?
- It is open source
- Extremely powerful
- Comprehensive
- Commonly used tool
- Easy
What are the basic numerical operators?
^ = power * = multiplication / = division \+ = summation - = subtraction
What are the logical operators?
& = and | = or ! = not
What are R functions?
Functions undertake calculations, and require a set of parentheses after their name and the arguments listed within them.
What are variables?
They provide a way of labelling and storing information, and correspond to computer memory that is allocated to each bit of information.
What are the requirements for variable names?
- Starts with a letter
- Letters, periods, and numbers can be used
- An underscore can be used but should be avoided
- Cannot contain a space or other characters
- Cannot be a reserved word or function e.g TRUE
Advantages of variables?
- They can store multiple values
- Can be combined into data frames
What is a variable that contains one or more values called?
An atomic vector.
Which function creates vectors?
c()
What are the ways we can identify elements within a vector?
- Position number e.g boredom [1]
- Name e.g “boredom”
How can we select elements?
- Position number e.g boredom[-2] or boredom c(1,3)
- Logical values e.g boredom [c(TRUE, TRUE, FALSE)]
- Logical expressions e.g boredom[boredom
What are packages?
User-written collections of functions, data, and help documents that can be used in data analysis.
What is installing and loading a package?
Install: The package is in your computer
Load: The package is made available in R studio