R question
Homework 2
Your name
Honor code:
“I have neither given nor received unauthorized assistance on this assignment.” Type your initials here.
I receive help from "" and give help to "".
Please remember to add title and proper labels to your plot.
Problem 1 Create a vector of integers from 0 to 100 (inclusive) and assign it to the variable x. Multiple x by 2 and output the result. Extract the index of x with value larger than or equal to 90. Extract all the even numbers from x.
Problem 2 Draw a random sample with size 9 from a Bernoulli distribution and fill it into a 3by3 matrix X. Draw a random sample with size 12 from a Bernoulli distribution and fill it into a 3by4 matrix Y. Calculate the matrix multiplication between X and Y. What will happen if you use * to multiply X and Y? Why will this happen?
Problem 3 Look at the help document of mtcars data set. Print out the first few rows of the mtcars data. Find the indexes of rows with 6 cylinders and extract the mpg of the cars with 6 cylinders. Calculate the means and standard deviations of the mpg within each category of cylinders using mean() and sd() function.
Problem 4 Order the mtcars dataset by mpg feature in mtcars and output a new datafame with rows ordered by mpg with decreasing order. Create a vector to store the values of hp for 10 cars with largest mpg and another vector to store the values of hp for 10 cars with smallest mpg. Calculate their mean and standard deviation.
Problem 5 Find four discrete features and use barplot() to show the distribution of all the discrete variables. Split the frame into a 2by2 using par(mfrow=c(2,2)) and generate all plots into the same frame.
Problem 6 Plot the histogram of hp by setting different number of breaks (breaks=10 and breaks=20) and put these two graphs into a single frame. Explain why these two histograms are different.
1
Problem 7 Find one continuous feature in mtcars dataset and make a boxplot of it for each engine type.
Problem 8 Create a scatter plot for mpg vs disp and a scatter plot for wt vs disp side-by-side in a single frame.
Problem 9 Load the MINST data set in keras package use barplot() to show the distribution of labels.
Problem 10 Random sample two row indexes by using sample() function, and extract the corresponding images. Use image() function to visualize the extracted images.
2
- Problem 1
- Problem 2
- Problem 3
- Problem 4
- Problem 5
- Problem 6
- Problem 7
- Problem 8
- Problem 9
- Problem 10