Skip to content
Snippets Groups Projects
Commit 340c7e3c authored by pfoo's avatar pfoo
Browse files

Update notebook and solutions

parent f8a6fe0c
No related branches found
No related tags found
No related merge requests found
...@@ -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.
......
...@@ -105,15 +105,6 @@ sapply(students, class) ...@@ -105,15 +105,6 @@ sapply(students, class)
``` ```
## 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.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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment