Question: R Coding Question 1 (a) Use the setwd() function to set your directory to a folder that you will be using for this assignment [2]

R Coding

Question 1

(a) Use the setwd() function to set your directory to a folder that you will be using for this assignment [2]

(b) Think of any 5 statistical distributions and the domain of their pdf's. Type out x1, x2, . . .,x5 as 5 different vectors. Also type out the parameters for each of these distributions 1, 2, . . ., 5. Type out the formula for the outputs y1, y2, . . .,y5 as a function of xi and i . Some of the distributions you choose will have more than one parameter. [5]

(c) For each of the distributions above, write function that inputs only the parameters, and a vector of x values as arguments. Name the parameters accordingly. The function must return a list of y, x, n, and the parameter. [Hint: ?return, function, ?list, ?seq] [10]

(d) Provide short description of how you can extract values returned by a function after you have run a function with its arguments. Also explain why it would be necessary to extract these values. [5]

Question 2

Double click to open the following and use the following dataset (extracted from Excel) to answer the questions that follow:

Names,Surnames,Student Number

John ,,2O02112201

Sara,Jones, 20182OO123

James,Hannes,2018654781

Ntokozo,Ali,

Mohammed ,Smith,2018876554

Palesa,Rapelang,2018673074

(a) Save this dataset (Excel format) to your working folder and read the dataset into R using an appropriate name. [2]

(b) Input function that takes the a dataframe as an argument and cleans the the data. The function must return the following: 1. A vector ("list") of missing names Page 1 of 2 2. A vector ("list") of missing surnames 3. A vector ("list") of missing student numbers [Hint:?which, ?is.na, df[which(some_statement), some_column]]

(c) Besides missing student numbers, describe errors that you see in the student number column. (d) In the same function, clean the student numbers. Find the errors and then correct them. [hint: ?ifelse]

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 Mathematics Questions!