Multiplication, Divide, Addition, Subtraction, To the power of, Equal to, Not equal to
Placing a question mark before a function switches the bottom rightwindow to the help tab.
<-
Assigns a value to a named object. Called arrow.
Can also work with "=", but run into problems with this later when trying to use functions that require the use of "=".
# inside a code chunk
Makes that line a comment, so R will ignore that line. Comments are useful for reminding yourself of what your code is doing.
# outside a code chunk
Outside a code chunk it creates headings. ## would make a subheading, and so on and so forth with the more "#" used.
Named objects are case sensitive.
What does the dim() function do?
Can find out how many rows and columns there are for the data.
What do str() function or glimpse() function do?
Get a glimpse at the data.
What are reserved words?
Are a set of words that you can't use as names, but R will tell you if you make the mistake of trying to name a variable after one of these.
R code is conducted in the “Console”.
However, R code can be carried out somewhere else before sent to the console.
Where is the console?
Bottom left window
Where is the Environment and what does it do?
Top right window, and shows everything that is stored in R.
How to run a code chunk, and why it needs to be done:
Enter what required in the new R script. Hit Ctrl + Enter on the top line, or alternatively hit “Run”.
Each line must be “entered” or “ran”, otherwise R doesn’t know what (e.g.) y means.
Where is the editor and what does it do?
Top left hand window, where you write and edit code
The bottom-right window shows the plots that you create, the files in your project, and other functions.
R Packages:
We can install packages, but to actually use the package we need to use library().
To install: install.packages()
To store a sequence of numbers into R (as seen singularly with arrow), we combine the values using the combine function ( c ) and give the sequence a name.
A sequence of elements all of the same type is called a vector
Vectors can also be words, as long as they are all of the same type
R markdown: information
Combines the analytical power of R and the utility of a text-processor. Can produce a report, containing all our analysis and written text, without having to copy results over to a Word document. Essentially involves normal written text embedded with “code-chunks”. The document can then be made into a PDF or HTML.
In the environment you can check what class something in the environment is stored as.
Ways of achieving different text styles in a report:
^2^ makes it small and high.
~~text~~ for strikethrough
Embolden = **text** or __text__
Italicise = *text* or _text_
To declare something as a factor use factor().
e.g. mydata$Degree <- factor(mydata$Degree)
Double (dbl) and numeric (num) are terms for numbers.
What do you use $ for?
To specify a column within a dataset.
What is the purpose of [ , ]?
To show a distinct point in a data set.
i.e. [3,4] shows you the value in the 3rd row and 4th column.
Just the 3rd row = [3,]
4th column = [,4]
Can change the value in [3,4] using the arrow.
Can add a new column using $ and the arrow to specify what is in that column. Number in the list has to match the number of rows.
Can use list() instead of c()
For a summary of the data:
summary()
min()
max()
What is a factor in R?
A factor in R is a data structure that is used to store and categorize categorical data, which are variables that take on a limited number of different values. Factors can store both integers and strings, and have a levels attribute that holds all the possible values of the factor.
Factorise and show the "somevariable" variable in the "somedata" dataframe