Question: For the problems which involve writing R code, you will need to submit the R markdown file and outputted pdf to Canvas. See additional instructions

For the problems which involve writing R code, you will need to submit the R markdown file and
outputted pdf to Canvas. See additional instructions below regrading other files to be submitted. Be
sure to include your name in the header of your RMD program.
1. Create a function that takes a vector of numbers and returns either the median of the vector or
the average value. If the vector contains an odd number of elements, output the median.
Otherwise, if the vector contains an even number of elements, output the average.
a. This function name should be called `mean_or_median`. You need to calculate the mean
using the mathematical formula, not using the mean() function.
b. Test your function on the following 3 vectors:
i. c(4,15,2,37,182,3876,29,18)
ii. rep(c(23,15,23),15)
iii. c(72.25,281.3,27361.2357,926153.15,(1/3))
2. Consider the computer data. Complete the following:
a. Return the indices of any computer codes that start with A or B followed by any digit.
b. Create a new variable NUMCODE that is only the numerical components of each
computer code (remove all letters).
c. Create a new dataset name LETTER1 that is only rows where the computer code starts
with a letter.
3. Create a function called first that takes a vector and outputs a new vector. For each element of
the vector, if the first character of the string is a digit, in that index of the new vector, assign the
letter D. If the first character of the string is a letter, assign whatever that first letter is to the new
vector index.
a. Test this function on the computer code column of the computer data.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!