Homework 2
Homework 2
Due: 2020-08-25, 11:59p
For this homework you should submit a ZIP archive called
yourname.zip
with the following files.
- A document file (TXT, MD, RMD, IPYNB, PDF, DOC, DOCX) with answers to the first two items.
- Two Markdown (MD) files, called
pancakes.md
anddishname.md
.
In this homework we will gain familiarity with some basic R operations, and using Markdown.
1. Using help (25%)
Show both the code and the output for each of the following steps.
- Assign 27/7 to a variable called
x
, and print the result. - Read the documentation on the
round
function usinghelp
(do not include output). Name the compulsory arguments and optional arguments for this function. - Round off
x
to the nearest integer. - Round
x
to two decimal places. - Round up
x
to the nearest integer. - What happens if you use
as.integer
onx
?
2. Data frames (25%)
This homework refers to the pancake recipe. You will convert the ingredient list into a data frame. Each item in the ingredient list has a name, units, and amount
Show both the code and the output for each of the following steps.
- Create three vectors: ingredient name, units, amount.
- Make a data frame out of them, and print.
- Double the recipe and print the result (hint: you have to multiply just the amount, and nothing else).
3. Using Markdown (50%)
Here is the raw Markdown for the pancake recipe.
# Whole grain pancakes
Makes about 10 pancakes.
## Ingredients
- 60g whole wheat flour
- 60g brown rice flour
- 1/8t salt
- 1t sugar
- 2t baking powder
- 200g whole milk
- 20g yogurt
- 50g (one) egg, beaten
- 50g vegetable oil or butter
## Process
- Preheat skillet on medium heat.
- Combine dry ingredients (flours, salt, sugar, baking powder) in bowl.
- Add yogurt and egg to dry ingredients; do not mix.
- Add 120g milk to mixture in bowl and mix till it becomes a thick mixture.
- Add remaining milk, and stir till just mixed; do not overmix.
- Brush oil on skillet; wait till it is hot (oil will start smoking).
- Pour batter onto skillet (adjust to desired size), and wait till
middle bubbles.
- Flip pancake, and wait till side is done.
- Serve with butter and maple syrup or jam.
## Notes
- You may substitute all-purpose flour for whole wheat flour, or
white rice flour for brown rice flour, but then it won't be a whole
grain recipe.
- The rice flour can also be replaced by wheat flour.
- The pancake recipe above is for 10 pancakes. Modify the recipe to
make it suitable for 20 pancakes (make sure you change the
ingredient list and the instructions appropriately). Make at least
one other change in the recipe by modifying ingredients or
instructions or the notes. Save as a text file in
Markdown
format called
pancakes.md
. - Use the Markdown template for the pancake recipe to write a favorite
recipe that you are comfortable sharing with the class. If you are
not into cooking, you can make a simple recipe, e.g. for boiling an
egg, making white rice, or making tea. Save it in a file called
dishname.md
. Make sure it has a title (name of dish), how many servings it makes, an ingredient list, a sequence of steps, and any notes.
4. Acknowledgments
Please cite persons or resources you used to complete the homework.