R Flashcards

1
Q

In R’s lattice, makes plots show up Top-> Bottom,

Left -> Right?

A

…, as.table = TRUE

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

dplyr version of:

merge(x, y, all.x=T, all.y = T)

A

full_join(x, y)

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

with stringr, return the 1st match for a regex?

A

str_extract(str, regex)

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

with stringr, replace each vowel in x with “-“?

A

str_replace_all(x, “[aeiou]”, “-“)

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

with stringr, replace 1 with one and 2 with two in x?

A

str_replace_all(x, c(1 = “one”, 2 = “two))

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

with stringr, return all matches in a string for a regex?

A

str_extract_all(x, regex)

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

dplyr version of:

merge(x, y)

A

inner_join(x, y)

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

In R’s plot, set number size at tick marks?

A

plot(…, cex.axis = number)

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

do with join operation:
flights %>%
filter(dest %in% top_dest$dest)

A

flights %>%

semi_join(top_dest)

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

In R, after xaxt = “n”, add ticks for the years 2008 and 2016?

A

axis.Date(1,
at = c(as.Date(“1/1/2008”), as.Date(“1/1/2016”)),
label = c(“2008”, “2009”))

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

In R, set the outer margin to leave 2 lines for text on Top and add “Title” there?

A

par(oma = c(0, 0, 2, 0))

mtext(“title”, outer = T)

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

With stringr, treat na as string?

A

str_replace_na()

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

With stringr, turn myVec (a vector) into one long string with no spaces?

A

str_c(myVec, collapse = “”)

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

In R’s plot(), set point type?

A

plot(…, pch = [0:255])

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

In R, add a surrogate key to dat?

A

dat %>%

mutate(surrogate_key = row_number())

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

Confirm tailnum is the primary key in planes in R?

A

planes %>%
count(tailnum) %>%
filter(n > 1)

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

In base R, what function is critical to unique arrangements of plots?

A

layout()

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

In R, add a line for a linear model with y & x?

A

abline(lm(y ~ x))

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

In R’s plot(), set axis label size?

A

plot(…, cex.lab = #)

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

stringr’s function to filter string matches?

A

str_subset()

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

Make tidy with tidyr:
tablea

country ‘99’ ‘00’ ‘01’
A x, y, z
B …
C

A

tablea %>%

gather(‘99’:’01’, key = ‘year’, value = ‘measure’)

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

with stringr, return the 1st match in each sentence?

sentences %>%
_______(“(a|the) ([^ ]+)”)

A

str_match

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

in base R, calculate the mean of variables in DAT at each level of FACTOR?

A

by(DAT, FACTOR, FUN = mean)

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

in R, add “label” on the right side of an existing plot in the outer margin?

A

mtext(“label”, 4, outer = TRUE)

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

In R, create a function that returns hello or goodbye based on user’s choice?

A

myFunc

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

In ggplot, how do you zoom in to the range 0-50 on the y-axis?

A

… +

coord_cartesian(ylim = c(0, 50))

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

In R, plot x as an overlay to an existing plot in the top right corner?

A

par(fig = c(0.5, 1, 0.5, 1), new = TRUE)

plot(x)

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

In R, how do you review this layout?

nf

A

layout.show(nf)

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

In R, how can you define a number of regions within the current device that can be treated as separated graphics devices?

A

split.screen()

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

Why manually call regex() in stringr functions?

A
To set arguments, which include:
ignore_case
multiline
comments
dotall
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

In R, create box plot from Y and FACTOR with notches?

A

plot(FACTOR, Y, notches = T)

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

In R, tx data from R to Excel?

A

1) write.table(data, “clipboard”, sep = “\t”, co.names = NA)

2) paste in Excel

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

In R, set orientation of #s on tick marks to always horizontal?

A

par(las = 1)

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

In R, remove white space before and after string?

A

trimws(string)

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

In R, sum of each row of matrix X?

A

rowSums(x)

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

In R, get names in a factor variable?

A

levels(factor)

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

In R, get # of names in factor variable?

A

nlevels(factor)

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

In R, reorder names in a factor variable?

A

factor(factor, levels = c(‘name1’, ‘name2’))

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

In R, turn factor names into integers?

A

as.vector(unclass(factor))

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

In R, set # of digits to 5 for any output?

A

options(“digits” = 5)

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

xyplot(root~week | plant):

add a line for a regression?

A

xyplot(root~week | plant,

-> panel.abline(lm(root~week))

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

In R, generate a q-q plot?

A

qqnorm()

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

In R, given events A and B, and sample space S, calculate probability of at least A or B occuring?

A

length(union(A, B)) / length(S)

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

Base R, return X where X is NA?

A

x[is.na(x)]

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

in R, reverse order of vector Y?

A

rev(Y)

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

In R, log to base n of x?

A

log(x, n)

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

In R, return max at each point of vector x?

A

cummax(x)

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

In R, what is the square root of x?

A

sqrt(x)

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

In R, difftime() vs. as.difftime()?

A

difftime() calculates the # of days between dates and as.difftime() creates a time object out of times, not dates.

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

In R, caluclate 25th percentile of x?

A

quantile(x, 0.25)

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

In R, generate a list of 4 1s, 4 2s, and so on up to 10?

A

rep(1:10, each = 4)

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

In R, calculate probability of A & B occuring within sample space S?

A

length(intersect(A, B)) / length (S)

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

In R, what function is equivalent to IF() formula in excel?

A

ifelse()

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

In R, get 5 items from vector Keys that allowed to grab the same value repeatedly?

A

sample(Keys, 5, replace = T)

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

Return df’s column B?

A

df$B

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

In R, name m’s columns AA, BB, CC?

A

colnames(m) GETS c(“AA”, “BB”, “CC”)

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

In R, probability of only A, not B within sample space S?

A

length(setdiff(A, B)) / length(S)

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

In R, return a histogram of vector x and then add dashed density lines?

A

hist(x)

lines(density(x), lty = “dashed”)

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

In R, return the dimensions of vector v?

A

dim(v)

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

In R, return df with the columns medians removed?

A

sweep(dat, 2, apply(dat, 2, median))

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

In R, test for normality of dat & describe null hypothesis?

A

shapiro.test(dat)

Null hypothesis = normally distributed

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

In R, X is weights and Y is heights. Create a scatter plot with X and Y labels and filled in dots?

A

plot(X, Y, xlab = “weight”, ylab = “height”, pch = 16)

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

Calculate the sum of the rows in m, by group?

A

rowsum(m, group)

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

What is the square root of x ?

A

sqrt(x)

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

In R, what is the working directory?

A

getwd()

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

In R, how do you create a list of words out of a string?

A

strsplit(str, “ “)

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

In R, get product of all values in vector X?

A

prod(x)

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

In R: add function to remove NAs?

newDat

A

na.omit(dat)

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

In R, x

A

x[which(abs(x-50) == min(abs(x - 50))]

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

In R, return just the means of Dat[,c(1, 2, 3)] by variables var5 and var6?

A

aggregate(Dat[,c(1,2, 3)], by=list(var5, var6), mean)

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

In R, how do you see data available in the loaded package “UsingR”?

A

data(package = “UsingR”)

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

In R, is it daylight savings right now?

A

as.POSIXlt(Sys.time())$isdst

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

In R’s legend, how do you set the fill color for symbols?

A

pt.bg = …

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

In R, set tick marks to be on the inside by the default length?

A

tcl = 0.5

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

When using dplyr’s arrange(), where do missing values end up?

A

the end

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

dates

A

strptime(dates, “%d%b%y”)

strptime(dates, “\%d\%b\%y”)

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

With dplyr, return all columns from flights except year through day?

A

select(flights, -(year:day))

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

With dplyr, return columns from flights with “ijk” in the name?

A

select(flights, contains(“ijk”))

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

dply command to reorder the rows?

A

arrange()

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

With dplyr, assign new names to specific columns while returning all columns?

A

rename()

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

With dplyr, put flights in descending order by distance?

A

arrange(flights, desc(distance))

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

With dplyr, put flights data in order by year, month and then day?

A

arrange(flights, year, month, day)

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

In R, find chi-square value for alpha, where x follows chi-square dist with 12 degrees of freedom?

A

qchisq(0.05, 12, lower.tail=F)

I think lower.tail = F is default…

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

In R, command to find what package is qplot is?

A

find(“qplot”)

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

In R, what function is useful for mathematical notations inside the plots functions?

A

expression()

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

In R’s lattice package, create a scatter plot for weight vs age given gender?

A

xyplot(weight ~ age | gender)

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

In ggplot, what grammar does size, shape, color and x/y locations relate to?

A

aesthetics… aes()

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

In ggplot, 2 ways to facet?

A

facet_wrap()

facet_grid()

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

What argument to jitter dots in geom_point?

A

position = “jitter”

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

ggplot(data = mpg, mapping = aes(x = displ, y = hwy) +
-> geom_point()
vs.
ggplot(data = mpg) +
-> geom_point(mapping = aes(x = displ, y = hwy))

A

Same graph, top uses global mapping and bottom uses local mapping

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

… + facet_grid(drv ~ .)

A

facets plot by drv along a column (up and down)

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

ggplot(data = diamonds) +
-> geom_bar(aes(x=cut, fill=clarity)

1) stacked bar chart?
2) 100% stacked bar chart?
3) Grouped bar chart?

A

position = …

1) no argument
2) “fill”
3) “dodge”

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

To plot hwy ~ displ from mpg:

ggplot(data = mpg) +
-> geom_point(? 1 = ? 2(x=displ, y = hwy)

A

? 1 mapping

? 2 aes

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

In R’s plot(), argument for no tick marks and no #?

A

xaxt = “n”, yaxt = “n”

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

In R, return items exclusive to A as compared to B?

A

setdiff(A, B)

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

In R, create a sample of 1000 families with 3 children and probability of 0, 1, 2, 3 boys as equal to 1/8, 3/8, 3/8, 1/8?

A

sample(0:3, size = 1000, prob = c(1/8, 3/8, 1/8, 3/8), replace = T)

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

In R, transpose matrix m?

A

t(m)

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

In R, show all possible scatterplot dot types?

A

plot(0:25, pch = 0:25

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

In R, 4 useful function for standard normal distribution?

A

pnorm(): cum probability
dnorm(): probability density
qnorm(): quantile function
rnorm(): random #s from distribution

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

In R, return Test’s attributes?

A

attributes(Test)

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

In R, how do you time a function?

A

system.time(functionName())

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

In R, create a QQ plot with a diagonal line for dat?

A

qqnorm(dat)

qqline(dat)

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

In R, check if file “fname.txt” exists in working directory?

A

file.exists(“fname.txt”)

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

A

A

lapply(list.object, length)

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

In R, with data.frame(DF), typeof(DF)?

A

“list”

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

In R’s data.frame(), suppress factor creation?

A

stringsAsFactors = F

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

In R, mean of each row of matrix X?

A

rowMeans(X)

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

In R, what are attributes?

A

metadata about objects

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

In R’s data frame df, what does length(df) return?

A

the same as ncol(df)

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

In R, set x’s “cust_attr” attribute?

A

attr(x, “cust_attr”)

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

In R, what function is useful for running random #s through a formula?

A

replicate()

remake this card…

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

In R, generate a plot a plot on a 3-d plane using vectors x, y, z?

A

persp(x, y, z)

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

What 3 attributes stay with modified objects?

A

Names - names()
Dimensions - dim()
Class - class()

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

In R, describe bootstrap test for testing a mean?

A

1) Create vector of means based on samples from true data -> x.bar
2) p.val testVal)]) / length(x.bar)

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

In R, given vector A, B, and function F that takes 2 arguments, create an array of dimensions (A, B) that is the result of function(A,B) for each cell?

A

outer(A, B, F)

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

In R, how do I print vector Y without printing missing values?

A

Y[!is.na(Y)]

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

not_cancelled %>%

-> count(dest)

A

A table showing count of not cancelled by dest

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

What 2 R packages are useful for larger, interactive heatmaps?

A

1) d3heatmap

2) heatmaply

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

In an R plot, set x & y labels color and font?

A

col. lab =

font. lab

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

In R, make a scatter.plot matrix of the data in obj?

A

pairs(obj)

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

dplyr’s measures of position:

1) x[1]
2) x[2]
3) x[length(x)]

A

1) first(x)
2) nth(x, 2)
3) last(x)

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

Geom for a tile plot?

A

geom_tile()

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

In R, calculate the mean of X without NAs?

A

mean(x, na.rm=T)

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

Rather than filtering out messy data, another–perhaps better–route?

A

Make the values missing

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

In R, find F value for alpha = 0.05 in the lower tail, where x follows f-dist and df1 = 5, df2 = 15?

A

qf(0.05, 5, 15)

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

In base R, x is a vector of age data. Create a histogram with an x-label, a title, and bins of size 20. Then add lines to the histogram?

A

hist(x, xlab=”Age” main = “title”, breaks = 20)

lines(density(x))

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

In RStudio, start a new script?

A

ctrl - shift - n

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

ggplot histogram?

A

geom_histogram()

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

Convert data frame to tibble?

A

as_tibble()

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

ggplot frequency polygon?

A

geom_freqpoly()

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

not_cancelled %>%

-> count(tailnum, wt=distance)

A

A table showing miles flown by each tailnum among not_cancelled

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

With dplyr, return dat’s columns var1, var2, var3?

A

select(dat, num_range(“var”, 1:3))

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

A function useful for 5<=x<=10?

A

between(x, 5, 10)

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

In base R, change the color of the axes?

A

par(fg = )

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

In R, return items in both A and B?

A

intersect(A, B)

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

ggplot’s bar graph?

A

geom_bar()

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

readr’s parsing functions when the data are already read into R?

A

parse_*()

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

delays ?

  • > filter(n > 25) ?
  • > ggplot(aes(x=n, y=delay)) ?
  • > -> geom_point(alpha = 1/10)
A

1) %>%
2) %>%
3) +

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

Create tibble from individual vectors?

A

tibble()

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

In readr, read in txt.csv and identify the comment lines as starting with #?

A

read_csv(“txt.csv”, comment = “#”)

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

in readr functions, don’t read first 5 lines?

A

skip = 5

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

In R, return 50th percentile of x?

A

median(x)

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

What ggplot function is critical for horizontal bar chart?

A

coord_flip()

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

In dplyr, how do you remove grouping?

A

ungroup()

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

In RStudio, send previously sent chunk from editor?

A

ctrl - shift - p

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

What is geom_bin2d() and geom_hex()?

A

Divides coordinate plane into 2d bins and uses fill color to show density

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

ggplot(smaller, aes(carat, price)) +

-> geom_boxplot(aes(group = ???(carat, 0.1)))

A

cut_width

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

tidyverse package for querying databases?

A

DBI

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

tidyverse package to read in SPSS, Stata, or SAS files?

A

haven

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

Using geom_point(), add transparency?

A

alpha = ..

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

readr’s identify encoding?

A

guess_encoding()

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

What are the main differences between data.frame and tibble?

A

1) printing

2) subsetting

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

print(flights, 1? = 10, 2? = 3?)
1=argument for number of rows
2=argument for number of columns
3=argument for all columns

A

1) n
2) width
3) Inf

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

For a density plot (frequency polygon) in ggplot:

ggplot(data = diamons, aes(x=price, y=1?)) +
-> 2?(aes(color=cat), binwidth=500)

A

1) ..density..

2) geom_freqpoly

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

In R, return the mean of each column in matrx x?

A

colMeans(x)

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

In R, create a boxplot of age data in x?

A

boxplot(x)

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

In R, return the sum of columns in matrix m without colSums()?

A

apply(m, 2, sum)

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

In R, test if x is TRUE?

A

isTRUE(x)

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

In dplyr, return flights where month equals the last 6 months of the year?

A

filter(flights, month %in% 7:12)

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

dplyr command to pick variables by name?

A

select()

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

dplyr command to operate on data group-by-group?

A

group_by()

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

R shortcut for

A

alt + -

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

dplyr command to pick observations by value?

A

filter()

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

In R, view list of functions and data in package “spatial”?

A

library(help = spatial)

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

With dplyr, return flights where month equals 1 and day equals 1?

A

filter(flights, month == 1, day ==1)

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

dply command to create new variables with functions of existing variables?

A

mutate()

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

What happens to NA values using dplyr’s filter()?

A

Filter excludes NA & False

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

With dplyr, return year, month, and day from flights?

A

select(flights, year, month, day)

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

With dplyr, return flight’s column time_hour and then all other columns?

A

select(flights, time_hour, everything())

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

In R, what argument is used for removing borders?

A

bty = ‘n’

border type…

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

In R, what are 2 ways to show overlapping dots in a scatterplot?

A

1) jitter(x) or jitter(y) or both

2) sunflowerplot(x, y)

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

In R, what is the default graphics window size?

A

7 inches by 7 inches

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

In R, what does which(requests %in% stock) return?

A

The index of items in requests that match an item from stock

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

In R, set the line thickness?

A

lwd = #

Line width…

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

In R, what does this do?

peas[1:length(peas) %% 2 ==0]

A

Returns objects in peas at even rows

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

In R, pmin(x, y, z)?

A

Returns the minimum of x, y, or z across each item in x, y, and z

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

In R, what is the difference between unique() and duplicated()

A

unique returns just the unique items while duplicated returns a boolean vector identifying duplicates

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

In R, what does this do?

peas[-length(peas)]

A

Returns peas without its last item

179
Q

In R, what functions are useful in naming rows or columns?

A

rownames()

colnames() or names()

180
Q

In R, how do I generate 1, 1.5, 2, 2.5, 3?

A

seq(1, 3, 0.5)

181
Q

In R, what function is helpful in making flat contingency tables?

A

ftable()

182
Q

In R, DF is data for 2 factor variables with 2 levels each, count up the combinations for dat1 & dat2?

A

table(dat1, dat2)

183
Q

In R, create a plot of x and y that looks like a line plot with no right border?

A

plot(x, y, type = “l”, bty = “c”)

184
Q

In R, how you view complete list of available packages?

A

library()

185
Q

With dplyr, by_day=group_by(flights, year, month, day):

return the average daily dep_delay?

A

summarize(by_day, mean(dep_delay, na.rm=T)

186
Q

In R, turn off x-, y-labels, and title?

A

ann = F

annotations…

187
Q

In R, remove all user-defined variables?

A

rm(list=ls())

188
Q

In R, how can you fine tune top, left, right and bottom axes?

A
axis()
     3
    _3_
2 |      | 4
   |_1 _|
189
Q

In R, counts

A

table(counts)

190
Q

In R, add a grid to a plot?

A

tck=1 (default is 0)

tick marks…

191
Q

In R, sub() vs. gsub()?

A

sub replaces 1st occurrence of a pattern; gsub replaces all occurrences of a pattern

192
Q

In R, set background color for graphics?

A

par(bg=”grey”)

background…

193
Q

In R, if is.ts(dat)=true, then what is returned for plot(dat)?

A

a timeseries graph, which is actually plot.ts(dat)

194
Q

In R, what function is superior to attach() due to environment issues?

A

with(data, function(…))

195
Q

In R, na._(x) will return x w/o NAs?

A

na.omit

196
Q

In R, sort DF by Var1, Var2, and then Var3?

A

DF[order(DF$Var1, DF$Var2, DF$Var3)]

197
Q

In R’s lattice, create a box and whisker plot of Growth vs. Water and Daphnia given detergent?

A

boxplot(Growth ~ Water + Daphnia | Detergent)

198
Q

In R, standardize dat’s columns 2:3?

A

scale(dat[,2:3)

199
Q

In dplyr, create new variables and get rid of all others?

A

transmute()

200
Q

read_csv(“challenge.csv”, 1? = 2?(x = col_double(), y = col_date()))

A

col_type = cols

201
Q

Geom for a boxplot?

A

geom_boxplot()

202
Q

In R, transfer data from Excel to R?

A

Copy from Excel and readClipboard()

203
Q

With dplyr, return flights columns that end with “es”?

A

select(flights, ends_with(“es”))

204
Q

In R, return p-value when observed chi-square is 14.56 and df = 7?

A

1 - pchisq(14.56, 7) or

pchisq(14.56, 7, lower.tail = F)

205
Q

In R, how do you prepare to make a 4 plots on the same output?

A
par(mfrow = c(2, 2)) (row)
par(mfcol = c(2, 2)) (column)
206
Q

In R, justify text w/i the text() function?

A

adj = c(x, y)

207
Q

In R, x

A

DOTplot(x)

208
Q

In R, when is the argument used to chane the plotting symbol color?

A

When pch = 21:25

209
Q

In R, rows in DF whereVar1is greater than its median and Var2 is True?

A

DF[DF$Var1 > median(DF$Var1) & Var2 == T]

210
Q

In R, x

A

x[-which(is.na(x))]

211
Q

In R, N

A

x.bar = c()
for (i in 1:N){
-> x x.bar[i] = mean(x)
}

212
Q

Whenever you group_by(), what should you include?

A

counts using n()

213
Q

In R, if data are not normal and a t test is not possible, what is the appropriate test function?

A

wilcox.test()

214
Q

Apply readr parsing heuristics to the character columns in data frame?

A

type_convert()

215
Q

tidyverse package to read Excel?

A

readxl

216
Q

read_csv(“file.txt”, ? = “#N/A”

A

na

217
Q

In R, return the names of columns in a data frame?

A

names(table)

218
Q

Call df$x using pipe?

A

df %>% .$x

219
Q

In readr, parse_() vs. col_()

A

parse_*() when dealing with character vector

220
Q

In R, x

A

x[x %% 4 == 0]

221
Q

In R, name matrix m’s rows A, B, C, D?

A

rownames(m)

222
Q

dplyr command to collapse many values down to single summary?

A

summarize()

223
Q

With dplyr, number of unique items?

A

n_distinct()

224
Q

read_csv(“file.csv”, ? = F)

A

col_names

225
Q

In R, rotate text 45 degrees in a plot?

A

arg srt = #

226
Q

What are R’s 6 types of atomic vectors?

A
logical = T, F
integer = 1L, 2L, 3L
double (numeric) = 2.5, 4.5
Character = "a", "1"
complex &amp; raw, which are both rare
227
Q

In R, how do you view loaded libraries and environments?

A

search()

228
Q

ggplot(data = mpg, aes(x = displ, y = hwy)) +
-> geom_point(data = ?)

Only include subcompacts from class variable?

A

filter(mpg, class = “subcompact”)

229
Q

In R, sum x when x is less than 5?

A

sum(x[x<5])

230
Q

In R, how you save your existing history of commands to “fname”?

A

savehistory(file = “fname”)

231
Q

In R, cut(x, c(0, 2, 4, 6))?

A

Return a vector of length(x) that is a factor with (2, 4], etc., which is the same as 2 <= x < 4

232
Q

In R, add an arrow from (1,1) to (3,8)?

A

arrows(1, 1, 3, 8)

233
Q

In R, return months from dates? POSIXlt

A

dates$mon

234
Q

In R’s plot() or lines() function, what arguments sets line type?

A

lty

235
Q

In R, return a current date/time?

A

Sys.time() or date()

236
Q

In R’s plot, what argument for setting the scale for y?

A

ylim = c(0, 100) (example…)

237
Q

In R, return the day of the month for POSIXlt formatted dates?

A

dates$mday

238
Q

In R, output DF as “table.txt” that includes the names of rows and columns?

A

write.table(DF, “table.txt”, col.names = T, row.names = T)

239
Q

In R, how do you find all objects that match “lm”?

A

apropos(“lm”)

240
Q

In R, what function is useful for generating a pallete in grey scale?

A

grey()

241
Q

In R, capitalize all characters in a string?

A

toupper()

242
Q

In an R plot, how do you add dots from additional data?

A

points()

243
Q

In R’s hist(), set bin edges for count data with range 0:9 and width of 1?

A

breaks = (-0.5:9.5)

244
Q

In R, what is current value parameter ‘family’?

A

par(‘family’)

245
Q

In R, remove quotes around a string for printing?

A

noquote()

246
Q

In R, take a bunch of DVs across columns and make it 1 long vector?

A

stack()

247
Q

Reorder class based on hwy’s median?:

gglplot(mpg, aes(class, hwy)) +
-> geom_boxplot()?

A

ggplot(mpg) +

-> geom_boxplot(aes(reorder(class, hwy, FUN = median), hwy))

248
Q

In R, given dates of class POSIXlt, return seconds?

A

dates$sec

249
Q

In R, how you create a plot’s key?

A

legend()

250
Q

In R, return dates day of the year?

A

dates$yday

251
Q

In R, xv[which(abs(xv-108)==(min(abs(xv-108))]

A

Returns xv that is nearest 108

252
Q

In R, iris[,5] is flower names. Return index of rows that contain names that include a “a”?

A

grep(“a”, iris[,5])

253
Q

In R, what is ‘not’, ‘and’, and ‘or’ inside and outside an if operation?

A
not = ! and !
and = &amp; and &amp;&amp;
or = | and ||
254
Q

In R, set axis notation color and font?

A

col.axis, font.axis

255
Q

In R, return a vector of the position of a matched pattern in the text where it exists and a -1 otherwise?

A

regexpr()

256
Q

In R, view all available datasets included in installed packages?

A

data(package = .package(all.available=TRUE))

257
Q

In R, calculate the proportion of each item in a table based on the grand total?

A

prop.table(table) —- (no margin….)

258
Q

For R, what is a for script to print 1-5 one a time?

A

for (i in 1:5){

->print(i)}

259
Q

In R, quickly return a set of common statistics for obj?

A

summary(obj) or fivenum(obj)

260
Q

In R, return probability that x is <=4 based on a normal distribution where mean = 5 and sd = 0.125?

A

pnorm(4, mean=5, sd = 0.125)

261
Q

In R, find probability that -1

A

pt(1.5, 29) - pt(-1, 29)

262
Q

In R, return the sums of rows of M without using rowSums()?

A

apply(M, 1, sum)

263
Q

In R, what function can add words to a graph based on x and y coordinates?

A

text()

264
Q

Using R’s RColorBrewer package and the set2 pallette, create an 8-color pallette?

A

brewer.pal(8, “Set2”)

265
Q

In R, turn a vector of positive and negative numbers into -1s, 0s, and 1?

A

sign()

266
Q

In R, how do you restore a previously save R file called “Fname”

A

load(file = “Fname”)

267
Q

In R, what function is useful for printing a sentence as output?

A

paste()

268
Q

In base R, read in “fname.txt”, which is a file that has columns separated by whitespace & a header line?

A

dat

269
Q

In R, if t

A

t2

270
Q

In base R, return the positions of matched patterns in each string for all strings in S?

A

gregexpr(pattern, text)

271
Q

In base R, what is a 1st step when doing date calculations?

A

Convert objects to POSIXlt

272
Q

In R, tapply(temp, month, function(x) sqrt(var(x) / length(x)))?

A

Returns temp by month after function operation, which is the standard error.

273
Q

In R, what happens to a vector of words in a data frame? How do you go back?

A
  • coerced to factor

- as.character(factor)

274
Q

In R, how do you get the modulo of 119/3 and how do you get the integer quotient?

A

1) 119 %% 3 = modulo (remainder)

2) 119%/% 3 = integer

275
Q

In R, how do you generate n random numbers from a uniform distribution between 0 + 1?

A

runif(n)

276
Q

In R, closest integer to x between x + 0?

A

trunc(x) or floor(x)

277
Q

In R, how do you see an example for the “lm” function?

A

example(lm)

278
Q

In R, return the length of vector x?

A

length(x)

279
Q

In R, anti log of x?

A

exp(x)

280
Q

In R, see help pages for sum() function?

A

?sum

281
Q

In R, return vector of ranks of values in x?

A

rank(x)

282
Q

In R, sample variance of vector x?

A

var(x)

283
Q

In R, how do you combine vector x with vector y?

A

c(x, y)

284
Q

In R, vector of the product of all values of x up to that point?

A

cumprod(x)

285
Q

In R, dat

A

tapply(dat$height, list(dat$gender, dat$race), mean)

286
Q

Describe match(x, y)?

A

Returns y’s index numbers for each item of x that is in y

287
Q

With dplyr, return flights columns that have a title w/ a repeated character back to back?

A

select(flights, match(“(.)\1”)

288
Q

Five ways to subset a tibble?

A

1) .$name-vector
2) .[[‘name]]-vector
3) .[[position]]-vector
4) .[‘name’]-tibble
5) .[position]-tibble

289
Q

In R, set the size of the margin around the plot based on lines of text?

A

par(mar = c(bottom, left, top, right))

290
Q

In R, sum each column of matrix x?

A

colSums(x)

291
Q

In R, how do you remove the variable x?

A

rm(x)

292
Q

In R, x

A

x >= 5

293
Q

In R, how can you enter values one at a time from input?

A

scan()

294
Q

In R, how do you view existing variables?

A

ls() or objects()

295
Q

In R, how do you see a list of built in datasets?

A

data()

296
Q

In R, smallest integer > x?

A

ceiling(x)

297
Q

In R, how do I return all of dat’s columns from row 4 or all of dat’s rows fromcolumn 10?

A

dat[4,]

dat[,10]

298
Q

In R, return vector of the cumulative sum of x?

A

cumsum(x)

299
Q

In R, round x to nearest integer?

A

round(x, digits = 0)

300
Q

In R, assign dat to a file I choose, which is a csv with headers?

A

dat

301
Q

In R, return the name of the day of the week for dates?

A

weekdays(dates)

302
Q

In R, x

A

stem(x)

303
Q

In R, how do you create a function that returns multiple variables?

A

Use return() with a list containing the variables to be returned

304
Q

In R, prepare to plot 16 graphs, 2 in each row?

A

par(mfrow = c(8, 2))

305
Q

In R, return a sequence of dates between 10/1/1997 and 10/1/1997, with a date every 3 months?

A

seq(as.POSIXlt(“1997-10-01”), as.POSIXlt(“2007-10-01”),

->”3 months”)

306
Q

In R, make a bar graph of the categorical data day with a label “A” on x-axis, a title “Title”, and “B” on y-axis?

A

barplot(day, xlab = “A”, ylab = “B”, main = “Title”)

307
Q

In R, right justify text in a graph and then left justify it?

A
par(adj = 1)
par(adj = 0)
308
Q

In R, correlation of vector x and y?

A

cor(x, y)

309
Q

In R, return min of vector X up to each point in vector?

A

cummin(x)

310
Q

In R, x

A

which(x<3)

311
Q

In R, return vector from 5 to 25 that increases by 0.25?

A

seq(5, 25, 0.25)

312
Q

In R, x

A

x[x<=50]

313
Q

In R, how do you force it to make you push enter subsequent graphs?

A

par(ask = TRUE)

314
Q

In R, return sorted version of x?

A

sort(x)

315
Q

In R, what function provides info about ow to cite R software?

A

citation()

316
Q

In an R plot, how do you add stepped lines that connect points?

A

lines(x, y, type = “s”)
S for up then over
s for over then up

317
Q

In R, return any item in A or B?

A

union(A, B)

318
Q

In R, return the positions in a vector of a matched pattern?

A

grep()

319
Q

In R, what are four useful functions for rounding?

A

round()
ceiling()
floor()
trunc()

320
Q

In R, which.max(x)?

A

Returns index of the maximum value of x.

321
Q

In R, vector’s 3 common properties?

A

Type - typeof()
Length - length()
Attributes - attributes()

322
Q

In R, how do you install and load a package?

A

install.packages(“package”)

library(package)

323
Q

In R, is any value greater than 0 in X?

Are all values greater than 0 in X?

A

any(X>0)

all(X>0)

324
Q

With R’s RColorBrewer package, create a 12-color pallette with the “Spectral” colors?

A

brewer.pal(12, “Spectral”)

325
Q

In R’s plot(), do not include any axis?

A

axes = FALSE

326
Q

In R, read in a csv file saved as “fname.csv”?

A

read.csv(“fname.csv”)

327
Q

In R, suppress the creation of the y-axis?

A

yaxt = “n”

328
Q

In R, given dates of class POSIXct, return the minutes object?

A

as.POSIXlt(dates)$min

329
Q

In R, view the components of a list?

A

unlist(list)

330
Q

In R, sort dataframe DF by the variables CARS?

A

DF[order(DF$CARS,]

331
Q

In R’s plot(), argument for the label on the x-axis?

A

xlab = “label”

332
Q

In R:

union(A, B) vs intersect(A, B) vs setdiff(A,B)

A

union provides all items from A and B
intersect provides items that are in A and B
setdiff returns items in A that are not in B

333
Q

In R, prepare to overlay existing plot with another plot?

A

par(new = TRUE)

334
Q

In R, test whether 2 items/sets are equal?

A

setequal(a, b)

335
Q

In R, set the font to serif for plotted text?

A

par(family = ‘seriff’)

336
Q

In base R, return items that match a pattern?

A

grep(pattern, vector, value = T)

337
Q

In ggplot, add labels?

A

labs()

338
Q

In R, create a vector of A, B, C that each repeat 4 times?

A

gl(3, 4, labels = LETTERS[1:3])

339
Q

In R, what is coplot()?

A

coplot(y~x|z) returns multiple scatter plots y vs x at various ranges of z.

340
Q

In R plot, set title color and font?

A

col. main =

font. main =

341
Q

In R’s plot what function is useful for drawing the area under the curve?

A

polygon()

342
Q

In R’s plot, plot labels L using X and Y, centered on X, placed half a character below original points?

A

text(X, Y, labels - L, pos = 1, offset =0.5)

position refers to first position, X

343
Q

In base R, how do you join strings?

A

paste()

344
Q

In R’s lattice, draw a histogram for minTemp given month?

A

histogram(~minTemp | month)

month must be a factor…

345
Q

In R, how can you point and click on the location you want a legend?

A

locator(1) as position argument

346
Q

In R’s graphs change the box line color?

A

fg =

347
Q

In R, what is the probability of A given B within sample space S?

A

(length(intersect(A,B)) / length(S)) /

length(B) /length(S)

348
Q

In R, what function is useful for creating file paths?

A

file.path()

349
Q

In ggplot, describe the 7 parameters for making any plot using a generic example?

A

ggplot(data = DATA) +
GEOM_FUNCTION(aes(MAP), stat = STAT, position = POSITION)+
COORDINATE_FUCTION +
FACET FUNCTION

data, geom, map, statistic, position, coordinate, facet

350
Q

In R, return the hour object for right now?

A

as.POSIXlt(Sys.time())$hour

351
Q

In R, sort dataframe DF by Var1 in reverse order?

A

DF[rev(order(DF$Var1)),]

352
Q

In base R, what function is useful for counting letters in a string?

A

nchar()

353
Q

In R plot, set subtitle color and font?

A

col. sub =

font. sub =

354
Q

In R, return dates day of week?

A

dates$wday

355
Q

In R: what function is for applying functions to rows/columns of a matrices of dataframes?

A

apply()

356
Q

In R: what function is for applying functions to vectors?

A

sapply()

357
Q

In R: what function is for applying functions to lists?

A

lapply()

358
Q

In R: what function is for applying functions to a DF?

A

tapply()

359
Q

In R’s plot(), set plot char size?

A

argument cex =

360
Q

In base R, extract from STRING the characters from M to N?

A

substr(M, N, STRING)

361
Q

In R, dates

A

strptime(dates, “%d/%m/%Y”)

362
Q

In R, reverse sort DF by factor Var1 and normal sort if by Var2?

A

DF[order(-rank(DF$Var1), DF$Var2)]

363
Q

With tidyr, merge table5’s century and year columns to make new_year column?

A

unite(table4, new_year, century, year)

364
Q

In base R, join Dat1’s Var1 and Var2 with Dat2’s Name1 and Name2, including incomplete cases?

A

merge(Dat1, Dat2, by.x = c(“Var1”, “Var2”), by.y =c(“Name1”, “Name2”))

365
Q

tidyr::unite’s default sep?

A

_

366
Q

tidyr function to replace missing values with last observation?

A

fill()

367
Q

Make tidy with tidyr:

TABLEA
Country->type->count
x -> cases -> #
y -> cases -> #
z -> cases -> #
x -> pop -> #
y -> pop -> #
z -> pop-> #
A

TABLEA %>% spread(key = type, value = count)

368
Q

With tidyr, 2 ways to set separates’s sep parameter?

A

1: regular expression
2: position (positive # = far left, neg # = far right)

369
Q

With tidyr, combine multiple columns into a single column?

A

unite()

370
Q

Default sep in tidyr’s separate function?

A

any non-alphanumeric character

371
Q

tidyr verb to deal with observations scattered across rows

A

spread()

372
Q

In R, how do you adjust the plotting region?

A

plt=c(BOTTOM, LEFT, TOP, RIGHT)

373
Q

In R, how do you set the fill color for boxplots, histograms, etc?

A

col =

374
Q

What tidyr verb to turn a variable spread across columns into a single column?

A

gather()

375
Q

With tidyr, split a ‘rate’ column (from dat), x/y, into 2 columns?

A

separate(dat, rate, into = c(“x”, “y”))

376
Q

tidyr’s function for making implicit missing values explicit?

A

complete()

377
Q

Stocks has year, quarter, and return, use tidyr to check for missing values?

A

stocks %>% complete(year, quarter)

378
Q

With tidyr, separate, pull, gather, and spread functions, re-evaluate column types?

A

convert=TRUE)

379
Q

In R’s plot(), set orientation of #s on tick marks?

A

the argument las =

380
Q

x

A

str_sub(x, 1, 3)

381
Q

3 ways to use ‘by’ in join operations from dplyr?

A

1) default, by = null, uses all variables that appear in both tables
2) character vector, by = ‘varname’, uses the variable name specified from both tables
3) 2 character vectors, by = c(‘a’ = ‘b’), use “a” from X and “b” from Y

382
Q

astr

A

“ater”

383
Q

In R, return the proportion of items in each group organized and computed by column, using the matrix dat?

A

prop.table(dat, 2)

384
Q

In R, how do you load the environment history saved in “fname”?

A

loadhistory(file = “fname”)

385
Q

dplyr version of:

merge(x, y, all.x = TRUE)

A

left_join(x, y)

386
Q

In R, create Y that is a sorted version x?

A

Y

387
Q

In R, how do you save existing environment objects to “fname”?

A

save.image(file=’fname’)

388
Q

In R, view history?

A

history(Inf)

389
Q

With stringr, return the start and end of first match in x?

A

str_locate()

390
Q

What is the explicit way to str_view(fruit, ‘nana’)?

A

str_view(fruit, regex(‘nan’))

391
Q

With stringr, return boolean vector for string matches?

A

str_detect()

392
Q

Two stringr functions to test regexp?

A

str_view()

str_view_all()

393
Q

With str_extract_all(), return a matrix result?

A

simplify = TRUE

394
Q

Using dplyr and stringr: return df$words where words is equal to “x$”

A

df %>% filter(str_detect(words, “x$”))

395
Q

In R, given FACTOR and Y, create a plot that shows the value of Y for each case with FACTOR?

A

stripchart(Y~FACTOR)

396
Q

Merge with dplyr:

flights %>%
-> _____(airlines, by = ‘corner’)

A

left_join

397
Q

str_sub(“Apple”, -3, -1)

A

plt

398
Q

In R, how do you save the object X to “fname”?

A

save(x, file = “fname”)

399
Q

To speed up stringr functions for simple searches, what do you replace regex() with?

A

fixed()

400
Q

What are dplyr’s filtering joins?

A

semi_join(x, y): keeps all in x that have match in y

anti_join(x, y): drops all in x that have match in y

401
Q

str_c(“p”, c(‘a’, ‘b’, ‘c’), ‘s’)?

A

‘pas’ ‘pbs’ ‘pcs’

402
Q

x %>% full_join(y)?

A

Keeps all observations of x and y

403
Q

In R v

A

matrix(R, nrow=3, byrow=TRUE)

404
Q

stringr’s version of nchar()?

A

str_length()

405
Q

with stringr, combine strings with no space?

A

str_c()

The default sep = “”

406
Q

x %>% right_join(y)?

A

Keep all of y’s observations

407
Q

With stringr, what are possible with boundary()?

A

character
line
sentence
word

408
Q

With stringr, identify the number of string matches?

A

str_count()

409
Q

dplyr version of:

merge(x, y, all.y=TRUE)

A

right_join(x, y)

410
Q

x %>% left_join(y)?

A

return all observations of x

411
Q

ggplot(dat, aes(x)) + geom_bar()

forcats: Add a line to prevent dropping levels of x that have no values.

A

… + scale_x_discrete(drop = FALSE)

412
Q

ggplot(relig, aes(tvhours, relig)) + geom_point()

forcats: Rewrite this to put relig in order of tvhours?

A

ggplot(relig, aes(tvhours, fct_reorder(relig, tvhours)))+

-> geom_point

413
Q

Using forcats, reorder FACTOR so that “Not Applicable” is the first category?

A

fct_releve(FACTOR, “Not Applicable”)

414
Q

forcats function to make legend colors match order of plotted objects?

A

fct_reorder2()

415
Q

gss_cat %>%

  • > mutate(marital = marital …???
  • > ggplot(aes(martial) +
  • > geom_bar()

Add forcats functions to get marital in order of increasing frequency on the plot

A

gss_cat %>%

  • > mutate(marital = marital %>% fct_infreq() %>% fct_rev()) %>%
  • > ggplot(aes(martial) +
  • > geom_bar()
416
Q

forcats function to adjust a factor’s levels?

A

fct_recode()

417
Q

forcats function to adjust a factor’s levels, while reducing the number of levels as well because you can pass a vector of levels for each new level?

A

fct_collapse()

418
Q

forcats function to aggregate smaller factor levels into an “Other” category?

A

fct_lump()

419
Q

lubridate function to get current date?

A

today()

420
Q

lubridate function to get current date-time?

A

now()

421
Q

lubridate function to create date from “2011-01-15”

A

ymd()

422
Q

lubridate function to create date from “Jun 15 2011”

A

mdy()

423
Q

lubridate function to create date from “15 April 2009”

A

dmy()

424
Q

lubridate function to create date-time from “2011-01-15 20:11:19”

A

ymd_hms()

425
Q

lubridate function to create date from month, day, and year spread across columns?

A

make_date(year, month, day)

426
Q

lubridate function to create date-time from month, day, year, hour, min, second spread across columns?

A

make_datetime(year, month, day, hour, minute, second)

427
Q

lubridate function to convert date to datetime?

A

as_datetime()

428
Q

lubridate function to convert datetime to date?

A

as_date()

429
Q

lubridate function to extract year from dt

A

year(dt)

430
Q

lubridate function to extract the full month name from dt

A

month(dt, label = T, abbr = F)

431
Q

lubridate function to extract the day of the month from dt

A

mday(dt)

432
Q

lubridate function to extract day of the year from dt

A

yday(dt)

433
Q

lubridate function to extract full day of the week name from dt

A

wday(dt, label = T, abbr = F)

434
Q

lubridate function to extract hour from dt

A

hour(dt)

435
Q

lubridate function to extract minute from dt

A

minute(dt)

436
Q

lubridate function to extract second from dt

A

second(dt)

437
Q

lubridate function to round dt

A

floor_date(dt, “week”)

438
Q

lubridate function to round dt

A

ceiling_date(dt, “month”)

439
Q

dt

A

year(dt)

440
Q

dt

A

update(dt, year = 2010, mday = 19)

441
Q

my_age

A

as.duration(my_age)

442
Q

my_age

A

my_age + dyears(2) + dweeks(7) + ddays(3)

443
Q

my_age

A

my_age + years(2) + weeks(7) + days(3)

444
Q

What is the difference between lubridate’s durations and periods?

A

durations use seconds and are exact, but can do unexpected things around day light savings time

periods work with “human” times and aren’t exact, but can do what you would expect around day light savings time (for example)