# Load Packages

```{r}
library(datasets)
library(tidyverse)
library(dplyr)
# run a single line of code:
# click on that line, then
# windows: control enter
# mac: command enter
```


# About R

Basic functions and language

```{r}
print('hello woRld')
birth_years <- c(1996, 2001, 1999)
print(birth_years)
birth_years
```

# Dataframe in R

```{r}
data.frame(person = c('Jack', 'Allen', 'Lisa'), birth_years = birth_years)

?data.frame
```

You could also check the use of a function or a package by searching in the help panel.

# Creating a new chunk in R

- manually click the green c button on the top right

- windows: control - alt - i

- mac: control - option - i




# Tidyverse

After function names do not leave any spaces.

Before and after operators (e.g. <-, =) leave spaces.

Put a space after a comma, not before.

Object names are all lower case, with words separated by an underscore.


# Markdown and Quarto

word

_word_

__word__

~~word~~

If you need R variables in text, you can do this: the birth_years are:
`r birth_years`

`r birth_years`

# Load mtcars Dataset

```{r}
mtcars <- mtcars %>% 
  mutate(am = as.factor(am))
# the above line of code mutates the am column of the mtcars dataset so that it is a categorical variable (factor)

mtcars <- mtcars %>% 
  mutate(vs = as.factor(vs))
mtcars$cyl
mtcars <- mtcars %>% 
  mutate(cyl = as.factor(cyl))
?as.factor

summary(mtcars)
```

# Dataset

## Description given by the author

```{r}
?mtcars
```

# First Look

Take a glimpse at the data.

1.  How many rows and columns are there in the "mtcars" dataset?
- 32 rows and 11 columns
2.  Any categorical variables?
- 2 (vs and am)
3.  Any numeric variables?
- 9 variables (everyone else)

```{r}
glimpse(mtcars)
summary(mtcars)

dim(mtcars)
```

# First and last few lines

```{r}
head(mtcars)
```

```{r}
tail(mtcars)
```


