@@ -101,28 +101,30 @@ Try to find the datatype of all columns in the `students` table by using the `s
...
@@ -101,28 +101,30 @@ Try to find the datatype of all columns in the `students` table by using the `s
```{r}
```{r}
# Write your code below
# Write your code below
sapply(students, class)
```
```
## 2.2.5 Summary of dataset
Use the `summary()` function to get a summary of all columns in the `menu` dataset.
## 2.2.5 Find unique values in a column
The `unique()` function in R can be used to find all unique values in a specific column in a table, e.g., `unique(tableName$columnName)`. Use the `unique()` function to find all values in the `Price` column in the `menu` dataset, without duplication.
```{r}
```{r}
# Write your code below
# Write your code below
```
```
## 2.2.6 Find unique values in a column
By using the `sapply()` function, find the unique values in each column in the `menu` table.
The `unique()` function in R can be used to find all unique values in a specific column in a table, e.g., `unique(tableName$columnName)`. Use the `unique()` function to find all values in the `Price` column in the `menu` dataset, without duplication.
```{r}
```{r}
# Write your code below
# Write your code below
```
```
By using the `sapply()` function, find the unique values in each column in the `menu` table.
## 2.2.6 Summary of dataset
Use the `summary()` function to get a summary of all columns in the `menu` dataset.
```{r}
```{r}
# Write your code below
# Write your code below
...
@@ -224,7 +226,7 @@ menu[3, 2] = 4.50
...
@@ -224,7 +226,7 @@ menu[3, 2] = 4.50
menu # Check to make sure the missing value is being replaced correctly.
menu # Check to make sure the missing value is being replaced correctly.
```
```
For a small dataset, the method above is plausible. For a larger dataset, the better way is to replace missing value(s) in a batch using the function `replace_na` in the `dbplyr` package.
For a small dataset, the method above is plausible. For a larger dataset, the better way is to replace missing value(s) in a batch using the function `replace_na` in the `tidyr` package.
```{r}
```{r}
library(tidyr) # The package which includes the replace_na function.
library(tidyr) # The package which includes the replace_na function.
Use the `summary()` function to get a summary of all columns in the `menu` dataset.
```{r}
# Write your code below
summary(menu)
```
## 2.2.6 Find unique values in a column
## 2.2.6 Find unique values in a column
The `unique()` function in R can be used to find all unique values in a specific column in a table, e.g., `unique(tableName$columnName)`. Use the `unique()` function to find all values in the `Price` column in the `menu` dataset, without duplication.
The `unique()` function in R can be used to find all unique values in a specific column in a table, e.g., `unique(tableName$columnName)`. Use the `unique()` function to find all values in the `Price` column in the `menu` dataset, without duplication.
...
@@ -131,6 +122,16 @@ sapply(menu, unique)
...
@@ -131,6 +122,16 @@ sapply(menu, unique)
```
```
## 2.2.5 Summary of dataset
Use the `summary()` function to get a summary of all columns in the `menu` dataset.
```{r}
# Write your code below
summary(menu)
```
## 2.2.7 Incomplete cases in dataset
## 2.2.7 Incomplete cases in dataset
In R, incomplete cases are rows in dataset that have `Na` value(s). These incomplete cases can be viewed using the function `complete.cases`.
In R, incomplete cases are rows in dataset that have `Na` value(s). These incomplete cases can be viewed using the function `complete.cases`.
...
@@ -226,7 +227,7 @@ menu[3, 2] = 4.50
...
@@ -226,7 +227,7 @@ menu[3, 2] = 4.50
menu # Check to make sure the missing value is being replaced correctly.
menu # Check to make sure the missing value is being replaced correctly.
```
```
For a small dataset, the method above is plausible. For a larger dataset, the better way is to replace missing value(s) in a batch using the function `replace_na` in the `dbplyr` package.
For a small dataset, the method above is plausible. For a larger dataset, the better way is to replace missing value(s) in a batch using the function `replace_na` in the `tidyr` package.
```{r}
```{r}
library(tidyr) # The package which includes the replace_na function.
library(tidyr) # The package which includes the replace_na function.