R Flashcards
(444 cards)
In R’s lattice, makes plots show up Top-> Bottom,
Left -> Right?
…, as.table = TRUE
dplyr version of:
merge(x, y, all.x=T, all.y = T)
full_join(x, y)
with stringr, return the 1st match for a regex?
str_extract(str, regex)
with stringr, replace each vowel in x with “-“?
str_replace_all(x, “[aeiou]”, “-“)
with stringr, replace 1 with one and 2 with two in x?
str_replace_all(x, c(1 = “one”, 2 = “two))
with stringr, return all matches in a string for a regex?
str_extract_all(x, regex)
dplyr version of:
merge(x, y)
inner_join(x, y)
In R’s plot, set number size at tick marks?
plot(…, cex.axis = number)
do with join operation:
flights %>%
filter(dest %in% top_dest$dest)
flights %>%
semi_join(top_dest)
In R, after xaxt = “n”, add ticks for the years 2008 and 2016?
axis.Date(1,
at = c(as.Date(“1/1/2008”), as.Date(“1/1/2016”)),
label = c(“2008”, “2009”))
In R, set the outer margin to leave 2 lines for text on Top and add “Title” there?
par(oma = c(0, 0, 2, 0))
mtext(“title”, outer = T)
With stringr, treat na as string?
str_replace_na()
With stringr, turn myVec (a vector) into one long string with no spaces?
str_c(myVec, collapse = “”)
In R’s plot(), set point type?
plot(…, pch = [0:255])
In R, add a surrogate key to dat?
dat %>%
mutate(surrogate_key = row_number())
Confirm tailnum is the primary key in planes in R?
planes %>%
count(tailnum) %>%
filter(n > 1)
In base R, what function is critical to unique arrangements of plots?
layout()
In R, add a line for a linear model with y & x?
abline(lm(y ~ x))
In R’s plot(), set axis label size?
plot(…, cex.lab = #)
stringr’s function to filter string matches?
str_subset()
Make tidy with tidyr:
tablea
country ‘99’ ‘00’ ‘01’
A x, y, z
B …
C
tablea %>%
gather(‘99’:’01’, key = ‘year’, value = ‘measure’)
with stringr, return the 1st match in each sentence?
sentences %>%
_______(“(a|the) ([^ ]+)”)
str_match
in base R, calculate the mean of variables in DAT at each level of FACTOR?
by(DAT, FACTOR, FUN = mean)
in R, add “label” on the right side of an existing plot in the outer margin?
mtext(“label”, 4, outer = TRUE)