R-Studio Flashcards
what can R be used for and and what is it very powerful in doing?
R is very powerful in analysing biological data efficiently, it can be used as a calculator, statistical modelling, to make graphs, for programming and much more
what type of language is R?
R is an object-oriented programming language i.e. one creates objects, gives them names - names that can be used for statistical tests or to make graphs/tables
we use a user friendly version: R-Studio
what do we do before we start processing data in R?
we must prepare our data in Excel before we export it to R
what are the four quadrants in the R-Studio:
console - where you write the code
graphical window - where the graphs show up
bottom right - variables, objects & formulas
how do you assign a value to a letter or word in order transform it into an object?
[name of object] <- [value to assign to object
what are the operators in R-Studio?
+ = addition
* = multiplication
/ = division
^ = raised to the power
sqrt = square root
how can we make R-Studio remember something?
through creating objects using the “<-“ method
why do we need to keep an eye on capitalisation?
because R is case-sensitive
how do we export our data from excel to R-Studio?
through creating a data frame using the following code:
beetle <- read.table(“location of excel file with desired data”, header = T, stringsAsFactors = T)
state what the following line of code does and dissect and explain each component of it:
beetle <- read.table(“C:/teaching/stats/lecture3/beetle_behaviour.txt” , header = T, stringsAsFactors = T)
this line of code steals all of your data from an excel sheet and places it neatly into R-Studio
beetle <- = simply the name of the data frame
read.table(…) = command to read in data frame with location of excel sheet
header = T (short for header = true): first row contains variable names
stringsAsFactors = T converts text in a data table to categorical variable (,factor’)
what do you always add at the end of your file name?
file name.txt
what is the purpose of the lines “header = T” & “stringsAsFactors = T”?
they confirm to the graph that the heading and columns are to be read correctly - T meaning ‘true’ where “header = T” confirms that the top row is the names of the variables and “stringsAsFactors = T” confirms that the factors (data points) lie beneath the headers in columns
what must you do once you have typed out your “read in data frame” line?
you must attach the data frame to the work space memory, i.e. make the data accessible through pressing enter after you’ve typed it to then, on the next line write: “attach(name of data frame)” which in this case would be: attach(beetle)
what do hashtags mean in R-Studio?
in R-Studio hashtags are used to make comments and will have no effect on the actual code
make the data accessible in R:
attach(name of data frame)
once you have made your data accessible to R through entering attach(name of data-frame) what must you enter and what will that give you?
once the data-frame is accessible, you type names(beetle) which will give you an output containing all of the variable names
once you have inputted your names(beetle) line to give you the name of all your variables, what must you now do and why?
immediately after names(beetle) you type head(beetle) which will automatically show the first rows of your data frame (the headings)
first three steps following the uploading of your excel file and why each step is important:
[beetle is the name of data-frame]
attach(beetle): this allows for your data to become accessible to the code
names(beetle): this gives the names of the variables in our data-frame “beetle”
head(beetle): this only shows the first rows of our data frame
how do you calculate the probability of a normal distribution in R?
using the command “pnorm”
what does R not like when it comes to excel sheets of data?
1) it does not like empty cells, therefore you must delete them of type n/a
2) it does not like headings with spaces, therefore if your header has two words - separate them with an underscore