R Flashcards

1
Q

mode()

A

Identifies the type of variable in the brackets
i.e. is is a character or numeric

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a vector?

A

A list of numbers or letters or character strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

c()

A

combines the string of data into a vector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

vectorname[n]

A

gives the nth value in the named vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

vectorname[n1 : n2]

A

Gives the n1th to n2th values in the vector, inclusive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

vectorname[-n]

A

Gives the whole of the named vector, without the nth value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

sum()

A

Gives sum of vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

mean()

A

Gives mean of vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

max()

A

Gives largest value of vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

median()

A

Gives median of vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

var()

A

Gives variance of vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

sd()

A

Gives standard deviation of the vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

name = function(x) actualfunction(variable)

A

Defines the name as a function which is another function applied to a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

sqrt()

A

Square roots value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

mad()

A

Gives the median absolute deviation (comparable to the standard deviation)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

shapiro.test()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

IQR()

A

Gives the interquartile range of the data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

summary()

A

Gives the minimum, maximum, median and mean as well as the 1st and 3rd quartiles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

barplot()

A

Gives a bar graph of a vector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

table()

A

Gives a frequency table of a vector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

length()

A

Gives the length of a vector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

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)

A

Labels the bars in the graph after the items in the labels vector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

hist()

A

Gives histogram.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

hist(GC, breaks = 50)

A

Allows us to chose how many bars in our graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

hist(GC, breaks = 50, col=’green’, xlab=”GC content”, ylab = “absolute Frequency”, main = “main title”, cex.main=2)

A

Gives hitogram with given number of bars and labels.
cex.main is the size of the title text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

dataset = read.table(“filename.txt”, header = TRUE)

A

Save data in dataset.
h=F is a viable alternative.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

attach(dataset)

A

Attaches all of the variables within the dataset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

stem()

A

Gives a stem and leaf plot of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

plot(a, b)

A

Gives a scatter graph comparing the two data sets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

plot(GC, reptime, main=”Title”, xlab=”GC content”, ylab=”Replication time”, pch=20, col=”red”)

A

Gives a scattergraph where pch controls the shape of the dots, 20 is circles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

data1 <- read.csv(“plant_data.csv”, header = TRUE)

A

Reads data from csv files

32
Q

boxplot(data1$height~data1$temp)

A

Gives a box and whisker plot.

33
Q

boxplot(data1$height~data1$temp, xlab=expression(“Temperature, “^o* “C”), ylab= “Height, cm”, col = “lightseagreen”, notch = T, las = 1)

A

Adds a o to the x axis label. The notches means that there is a 95% confidence interval on the interval. The las = 1 rotates the numbers on the y axis notches so that they are vertical.

34
Q

binom.test(no. successes, no.attempts)

A

Defines a binomal with probability of success, bounds of confidence and hypotheses.

35
Q

binom.test(no. successes, no.attempts, p of Ho)

A

Refines binomial expression by adding the expected p, which provides a null hypothesis.

36
Q

#

A

Gives comments

37
Q

sample(c(“heads”, “tails”), 1)

A

Gives one of the values in the array

38
Q

sample(c(“heads”, “tails”), 10, replace = TRUE)

A

Allows the “coin” to be flipped multiple times without using up the values in the array.

39
Q

sum(flips==”heads”)

A

Sums values within flips that are the same as the provided string

40
Q

head_count = function(k){
flips = sample(c(“heads”, “tails”), k, replace = TRUE)
sum(flips==”heads”)
}

A

defines function which takes a value k.

41
Q

{}

A

Allows for code across multiple lines

42
Q

heads = replicate(100, head_count(10))

A

Replicates the given function that number of times and collects the data.

43
Q

chisq.test(c(55, 45))

A

Runs chi squared test when one result is achieved 55 times and the other is achieved 45 times

44
Q

chisq.test(c(120, 480), p=c(1/6, 5/6))

A

Chi squared test where we provide probabilities for each outcome. As many outcomes can be listed as you like.

45
Q

chi = chisq.test(cdata)

A

Saves the chi squared test of data as its own variable.

46
Q

chi$expected

A

Gives the expected distribution of data.

47
Q

chi$observed

A

Gives the actual dustribution of data

48
Q

sum(((chi$observed - chi$expected)^2)/chi$expected)

A

Equation for chi squared.

49
Q

variable = scan()

A

Can fill a variable by writing a value then each value followed by a return and two returns to end it.

50
Q

t.test(iq, mu=100, alternative=”g”)

A

Does the t-test where mu is the average and g is an alternative hypothesis of the mean of the sample is greater than it should be and l would be lower.

51
Q

var.test(height$female, height$male)

A

Compares the variances of two groups of data to see if a t-test can be used.

52
Q

datafile = “http://personality-project.org/r/datasets/R.appendix1.text”
data.ex1 = read.table(datafile, header = TRUE)

A

Reads in data from online source, saves it to data.ex1

53
Q

aov(Alertness~Dosage)

A

Runs ANOVA on the data called. The data before the ~ is the dependednt variable, and the one after is the independent.

54
Q

anova1 = aov(Alertness~Dosage)
summary(anova1)

A

Creates a summary of anova data.
p value is given in Pr(>F) if below 0.05 we can reject there being no difference between the groups.

55
Q

TukeyHSD(anova1)

A

Runs a Tukey test on anova’d data. Shows p values of comparisons of datasets

56
Q

plot(TukeyHSD(anova1))

A

Plots graph of differences of means in data for the different groups compared.

57
Q

cor.test(Relaxed, Hyperventilated)

A

Runs Pearson’s correlation, gives correlation coefficient from -1 to +1

58
Q

cor.test(xaxis, yaxis, method=”spearm”)

A

Runs correlation tests as spearman’s rho.

59
Q

cricketmodel = lm(freq~temp)

A

Get linear regression in terms of temp.

60
Q

(cor(freq, temp))^2

A

Gives the multiple r-squared value - squared correlation coefficient.

61
Q

abline(cricketmodel)

A

Adds line of best fit to plot.

62
Q

count2 = na.omit(count)

A

Counts the number of N/As in the data.

63
Q

plot(log(count2$Area), log(count2$Population))

A

Plots the logs of data

64
Q

plot(log(count2$Area), log(count2$Population), xlab = expression (‘ln (Area, km^2)’), ylab = “ln(Population)”, col = “red”, las = 1)

A

plots scatter graph with labeled axis in red.

65
Q

kruskal.test(list(leach, stimpson)

A

Runs Kruskal’s test on data.
p of less than 0.05 means we can reject null hypothesis that all samples are drawn from same population.
Can use more variables.

66
Q

kruskal.test(allpay, bank)

A

Runs Kruskal’s test on data, can use comma or ~.

67
Q

library(dunn.test)

A

downloads the function dunn.test from the library

68
Q

dunn.test(allpay, bank, kw = TRUE, method = “boneferroni”)

A

compares allpay to bank using the bonferroni method.
kw = true meansn that kruskal-wallis is used as well.

69
Q

help(p.adjust)

A

calls up the R notes associated with that function.

70
Q

unstacked.reptime = unstack(dataset[,c(4, 1)])

A

Unstackes data from columns and adds it to a new variable.

71
Q

wilcox.test(first, second, paired = TRUE, exact = FALSE)

A

Runs paired wilcoxon test.
exact = false used when there is a lot of data, so exact p value cannoot be calculated.

72
Q

all = c(first, second)

A

Combines two vectors into one longer vector.

73
Q

friedman.test(all.leaks, allsuits, pilots)

A

runs friedman rank sum test. Here finds whether there is a difference between the leakage of at least one suit compared to another.

74
Q

friedman.test(all.leaks ~ allsuits | pilots)

A

Runs friedman test where:
pilots is the group
allsuits is the block

75
Q

pairwise.wilcox.test(all.leaks, allsuits, p.adjust.method = “bonferroni”,
paired = TRUE, exact = TRUE)

A

Test to do after a significant friedman result.