Foundations of Business Analytics

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/64

encourage image

There's no tags or description

Looks like no tags are added yet.

65 Terms

1
New cards

What does <- do in R?

assigns the value on the right to the object name on the left

2
New cards

What is a data frame

table with rows and columns

3
New cards

What is a function in R

a command that takes inputs and returns an output

The ones built into R, not made yourself e.g. tibble

4
New cards

What is a code chunk in a Quarto .qmd file

a block where you write R code that Quarto runs when rendering, and it shows the results (numbers/tables/plots) in the output.

5
New cards

What does Render do in Quarto?

runs all code chunks and converts the .qmd into an output document (e.g., HTML/PDF) with the results inserted

6
New cards

What is a package in R?

a collection of functions, data, and documentation that extends the basic capabilites of R

e.g. tidyverse

7
New cards

What does ```{r} mean in Quarto?

starts an R code chunk

8
New cards

What does #| eval: false do?

tells Quarto not to run this code chunk when rendering

9
New cards

What does library(readr) do?

  • It loads the readr package so you can use functions from it (including read_csv())


10
New cards

What does class() do

Tells you what type of object something is

Use it as quick sanity check right after importing data, to confirm R read it in the way you expected

e.g.

x <- 10 class(x) # "numeric"

11
New cards

What does names() do

Lists the column/variable names of a data frame

e.g. names(x) <- value

12
New cards

What does head() do

hows just the first few rows of a data frame (6 rows, by default)

preview your data without flooding the screen, handy for datasets with hundreds or thousands of rows


head(variable)

13
New cards

nrow()

Counts how many rows a data frame has

nrow(variable)

14
New cards

ncol()

Counts how many columns a data frame has

ncol(variable)

15
New cards

any()

Checks a condition across a whole column of values and returns a single TRUE if at least one value meets it, or FALSE if none do

e,g,

variable ←

completed = any(variable == "confirm")

16
New cards

sum()

adds up every value in a numeric column to give a single total.

e.g. sum(1, 2, 3, 4, 5, na.rm = FALSE)

17
New cards

ggplot()

Starts a new plot and tells R which dataset to build it from

18
New cards

aes()

Maps columns in your data to visual features of the plot

19
New cards

labs()

Adds or changes the text labels on a plot, such as the axis titles and the main title.

20
New cards

bins

how many bins to split the data into (for histogram)

21
New cards

facet_wrap()

Splits one plot into a grid of smaller plots, one panel per category.

22
New cards

geom_point()

Draws a scatter plot, one dot for every row of data

23
New cards

geom_smooth()

Adds a fitted trend line through your data.

24
New cards

method

the type of line to fit for trendline, for example "lm" for a straight regression line.

25
New cards

se

whether to show a shaded confidence band around the trendline. Set to FALSE to hide it.

26
New cards

alpha

the clarity of the points on scatter plot

27
New cards

scale_x_continuous()

Controls how the x-axis of a plot is drawn

28
New cards

trans

a transformation to apply to the axis, for example "log10"

29
New cards

labels

how to format the axis numbers, for example

30
New cards

scale_fill_okabe_ito()

Applies a colorblind-friendly set of colors to whatever is mapped to fill in your plot

31
New cards

theme_bw()

Switches the plot to a clean black-and-white theme

32
New cards

fct_infreq()

Reorders the categories of a variable by how often they occur, from most common to least common

fct_infreq(variable)

33
New cards

after_stat()

function used to map aesthetics to variables that are calculated internally by a statistical transformation (a "stat") rather than using raw columns from your dataset

34
New cards

dplyr

A package for wrangling data

35
New cards

filter()

Keeps only the rows that meet a condition you set, and drops the rest

filter(year %in% c(2022, 2023, 2024))

36
New cards

mutate()

Creates a new column in your data, or changes an existing one, based on pre-existing columns

Build new variables

e.g. mutate(equity = assets - liabilities)

37
New cards

select()

Keeps only the columns you name, and drops the rest.

e.g. select(variable, variable 2, variable 3)

38
New cards

arrange()

Sorts the rows of your data by one or more columns

e.g. arrange(desc(variable))

39
New cards

slice_max()

Keeps only the rows with the highest values of a column you choose

e.g. slice_max(variable)

40
New cards

group_by()

Splits your data into groups based on the values of one or more columns, without changing what the data looks like on screen.

group_by(column name) |>

41
New cards

summarise()

Collapses many rows into a single summary row, using calculations you choose, such as an average

e.g.

summarise(
ave_roic = mean(roic, na.rm = true),
sd_roic = sd(roic, na.rm = TRUE)
)

42
New cards

slice_head()

Shows the first few rows of your data, in the order they currently appear

slice_head(variable)

43
New cards

n()

Counts how many rows are in the current group

e.g.

variable |>
n()

44
New cards

desc()

Flags a column so that arrange() sorts it from highest to lowest instead of lowest to highest.

45
New cards

pivot_longer()

lengthen “short and wide” datasets by stacking values into a single column

46
New cards

pivot_wider()

shorten “long and narrow” datasets by spreading values into multiple columns

47
New cards

What makes data tidy?

Every tidy dataset has the same structure

Makes common R operations easier

48
New cards

!is.na

Checks for values that are not missing

49
New cards

$

Selects 1 variable in a dataset

50
New cards

==

boolean: ensures values on left = values on right

51
New cards

c()

combines arguments into a vector

52
New cards

!

The not operator

53
New cards

left_join

Keeps rows of

  • variable keep

  • other variables with join key


54
New cards

Dplyr Verbs that operate on rows

filter

arrange

55
New cards

Dplyr Verbs that operate on columns

mutate

select

56
New cards

Dplyr Verbs that operate on groups

group_by

summarise

57
New cards

Code for joins

new variable <-

variable keep |>

type of join(other variable, by = join_by(join key))

58
New cards

inner_join

Keeps only rows from both datasets that have the join key

59
New cards

full_join

Completely joins both datasets together with nothing lost

60
New cards

anti_join

A filtering join

Keeps rows of first dataset that don’t match those of second dataset

61
New cards

as_tibble

converts other data formats to tibble

62
New cards

transmute()

Adds new columns to dataset and drops all unmentioned original columns

Different to mutate since it doesn’t keep original columns

Same as mutate(.keep = "none")

e.g. transmute(equity = assets - liabilties)

63
New cards

coalesce()

finds the first non-missing value at each position

64
New cards

getSymbols

load and manage Symbols in specified environment

65
New cards

clean_names()

converts all column space to be lowercase, white space to underscores