Read Chapter 2 of R for Data Science (2e).
Carry out the R variables activities and exercises.
For more details read the help pages for arithmetic operators
(?Arithmetic
).
Refer to the R variables section and perform the following tasks.
Arithmetic operators and operator
precedence. Compute 1 + 3 - 5 * 8 / 2 ^ 2
and
1 + (3 - 5) * 8 / 2 ^ 2
.
Mathematical functions. Compute \((1.13+0.334)\times\exp(0.9)\)
Built-in constants. Compute \(\sin(\frac{23}{2}*\pi)\).
Scientific notation. Compute the number of hydrogen atoms in 1pg of hydrogen gas.
<-
Compute and store the number of
hydrogen atoms in a variable x
.
Good programming practice. Using descriptive variable names. Compute and store the number of hydrogen atoms in a variable with a descriptive name.
Benefits of variables. Store the
mass of hydrogen atoms in a variable mass
and Avogadro’s
constant in avo
. Compute the number of hydrogen atoms.
Then, in a separate code chunk, change the mass and
recompute.
Watch the basics of computer architecture video and answer the following questions.
Component | Function |
---|---|
Random access memory | |
Execute instructions to compute output from input data | |
Input devices | |
Convey the results/output of computation | |
Secondary storage |
What are the tradeoffs between RAM and secondary storage?
How many integers can a memory location with 6 bits hold?
A character is 1 byte long. How many characters can be represented?
Insert a code chunk to compute \(2^{3 \times 2 - 6/3}\).
Insert a code chunk to compute \(5.134 \times 10^{-3} + 1.087 \times 10^{-2}\). Use scientific notation.
Compute \(2^{\sin(\frac{3\pi}{2})}\).
Insert a code chunk and do the
following. Assign the value 0.3998
to a variable
radius
. Compute the circumference using the
radius
variable and assign the value to a new variable,
circumference
. Print out the value of
circumference
.
Compute the area of the circle
using the radius
variable and assign to a third variable
area
. Print out the area.
Change the radius to \(3.1122 \times 10^4\) and recompute the circumference and area and print their values out.