Starting from:

$30.99

STAT823- Homework 2: R Objects Solved

Directions
Launch RStudio and open a new RMarkdown file or use the class RMarkdown template provided and save it on your working directory as a .Rmd file. At the end of the activity, save your pdf generated from RMarkdown+Knitr and submit it in the Blackboard dropbox.

Show all your work. Late submission will attract a penalty of 10 points per day after the due date.

If you have questions, please post them on the lesson discussion board.

 

1.    (a) Create a vector of length 10 and fill it with a sequence of integers.

(b) Coerce the vector into a matrix of 5 rows and 2 columns. (c) Name the columns of the matrix "A" and "B".

2.    Assume that we have recorded the names and ages for four people: James is 27, Art is 42, Kate is 29, and Alex is 33.

(a)     Create a vector of names and a vector of ages from the data, making sure that you keep the ordering of the elements consistent.

(b)     Use the class() function to print the class metadata R has stored for each vector.

 

(c)      Using data.frame(), combine the two vectors into a dataframe and name the columns something informative. Print out the dataframe.

3.    A hypothetical data with heights (in cm) and weights (in kg) of 10 family members are shown below:

 

                                                                                             height (cm)      weight (kg)

Niece
120
22
Son
172
52
GrandPa
163
71
Daughter
158
51
Yai
153
51
GrandMa
148
60
Aunty
160
50
Uncle
170
67
Mom
155
53
Dad
167
64
(a)     Create a vector called ‘ht’ corresponding to the heights of the 11 family members. Assign the names of the family10 members to the ‘names’ attribute of this vector.

(b)     Create a vector called ‘wt’ corresponding to the family member’s weights.

(c)      Compute the body mass index (BMI: units should be kg/m2) of each person where BMI = weight/height2.

(d)     Identify the persons who have the lowest and highest BMI and calculate the standard deviation of the BMI.

 

More products