R Flashcards
mode()
Identifies the type of variable in the brackets
i.e. is is a character or numeric
What is a vector?
A list of numbers or letters or character strings
c()
combines the string of data into a vector.
vectorname[n]
gives the nth value in the named vector
vectorname[n1 : n2]
Gives the n1th to n2th values in the vector, inclusive.
vectorname[-n]
Gives the whole of the named vector, without the nth value.
sum()
Gives sum of vector
mean()
Gives mean of vector
max()
Gives largest value of vector
median()
Gives median of vector
var()
Gives variance of vector
sd()
Gives standard deviation of the vector
name = function(x) actualfunction(variable)
Defines the name as a function which is another function applied to a variable
sqrt()
Square roots value
mad()
Gives the median absolute deviation (comparable to the standard deviation)
shapiro.test()
Applies the shapiro test to the data, comparing it to a normal distribution.
Lower p value than 0.05 lets us reject the null hypothesis.
IQR()
Gives the interquartile range of the data
summary()
Gives the minimum, maximum, median and mean as well as the 1st and 3rd quartiles.
barplot()
Gives a bar graph of a vector.
table()
Gives a frequency table of a vector.
length()
Gives the length of a vector.
labels = as.vector(c(list of the names for the bars)
barplot((data in graph), names.arg = labels, xlab = name of x axis, ylab = name of y axis)
Labels the bars in the graph after the items in the labels vector.
hist()
Gives histogram.
hist(GC, breaks = 50)
Allows us to chose how many bars in our graph.
hist(GC, breaks = 50, col=’green’, xlab=”GC content”, ylab = “absolute Frequency”, main = “main title”, cex.main=2)
Gives hitogram with given number of bars and labels.
cex.main is the size of the title text.
dataset = read.table(“filename.txt”, header = TRUE)
Save data in dataset.
h=F is a viable alternative.
attach(dataset)
Attaches all of the variables within the dataset.
stem()
Gives a stem and leaf plot of data
plot(a, b)
Gives a scatter graph comparing the two data sets.
plot(GC, reptime, main=”Title”, xlab=”GC content”, ylab=”Replication time”, pch=20, col=”red”)
Gives a scattergraph where pch controls the shape of the dots, 20 is circles