1/39
Looks like no tags are added yet.
R code chunks in R Markdown
Sections where R code can run inside the document ({r} ...).
Purpose of R Markdown
Combine text + code to create reproducible reports (PDF/HTML/Word).
echo=FALSE
Hides the code, but shows the results.
eval=FALSE
Shows code but does not execute it.
message=FALSE and warning=FALSE
Hides messages & warnings in the output.
cache=TRUE
Reuses previously stored results to speed up knit time.
How to plot a graph with hidden code
```{r, echo=FALSE, message=FALSE, warning=FALSE}
Importance of version control
Tracks changes, rollback versions, supports collaboration & branching.
Initial Git configuration commands
git config --global user.name "Name"
git config --global user.email "email"
git fetch
Downloads changes from remote — does not merge.
git pull
Fetch and merge remote changes into local branch.
git clone URL
Makes a full local copy of a remote repository.
File states in Git
After committing a file, its status
Unmodified.
Why use branching?
Develop features/experiments without affecting main working code.
Command to check file status
git status.
How to ignore files in Git
Add patterns to .gitignore.
Difference between redirect and append
> — overwrite>> — append
Pipe operator in Linux
| — send output of one command to another.
chmod 700 file
Only owner can read, write, execute.
Main atomic data types in R
numeric, character, logical, integer, complex.
Difference: NA vs NULL vs NaN
What is a pure function?
Output depends only on inputs, no side effects.
Anonymous function
A function with no name, usually inline:
function(x) x^2
.
Create a sequence from 0 to 100 by 2
seq(0, 100, by=2).
Repeat 1 three times
rep(1, 3).
Main indexing start in R
1 (not 0!).
What does %>% do?
Pipes data into the next function.
Functions of filter(), select(), mutate(), summarise(), arrange()
Extract airline, model, tailnum & manufacturer for dest="IAH" (concept)
Join flights + planes + airlines, then filter dest == "IAH".
What does anti-join do?
Returns rows in left table with no match in right table.
How does inner join work?
Only retains rows with matching key values in both tables.
apply vs sapply vs tapply vs mapply
Difference between ggplot() and plot()
ggplot uses layered grammar of graphics; plot is single-call base graphics.
Basic scatter in ggplot
ggplot(df, aes(x,y)) + geom_point()
.
Good plotting practices
Clear labels, avoid clutter, focus on one message.
What is facetting used for?
Split into multiple small plots by a grouping variable.
for loop vs while loop
for = iteration over fixed sequence
while = runs until condition false.
What is an error message?
Code cannot run until the issue is corrected.
Steps to load, examine, arrange, analyse
read.csv() → head()/summary() → tidyverse verbs → plots/models.