Question: Data Frame Maker 2 # Your second function for this # assignment, df.maker2() should: # (1) Be named df.maker2(). # Please follow these instructions: #

Data Frame Maker 2 # Your second function for this # assignment, df.maker2() should:

# (1) Be named df.maker2().

# Please follow these instructions: # (2) Have adequate documentation for # each line of code in the body # of your df.maker2() function.

# Please follow these instructions: # (3) Call the following vector.maker() # function inside the body of your # df.maker2() (so you must read the # following vector.maker() function # into your R session first) like this:

# argument x is a random sample of from # 5 to 10 vector.maker <- function(x=sample((5:10),1)) { # vec is a list of three components: # (1) x unique numbers from 1 to 100: vec <- list(sample(1:100,x), # (2) x unique lower case letters # from a to z: sample(letters,x), # and (3) x random values of TRUE # and FALSE: sample(c(rep(TRUE,25),rep(FALSE,25)),x)) # This last line (which is what the function # vector.maker() returns) randomly selects one # of the three components from vec and 'unlists' # that component, that is, converts it from a list # to a single vector: unlist(sample(c(vec[1],vec[2],vec[3]),1)) }

Numbers <- (5:10)

# Try it out several times to understand what # it does: vector.maker()

# HINT: Inside your df.maker2() function # you might fix the number of x to 5 like: vector.maker(x=5)

# (4) df.maker2() accepts a variable # number of input vectors. HINT: Use # the ellipsis argument like:

df.maker2 <- function(...){ # < you need to insert your code here > }

# This is a requirement for df.maker2() # (5) If the number of vectors read into # data.maker2() as arguments is less # than 2, then data.maker2() self-generates # from 2-9 additional vectors of # different (random) modes. HINT: you # will need to use an If-Else statement # inside of your df.maker2() function.

# This is a requirement for df.maker2() # (6) If the number of vector read into # data.maker2() is 2 or more, it simply # returns a data.frame with each of those # input vectors as columns.

df.maker2 <- function(...){ # This line makes a list out of # your input vectors. Each input # vector becomes a component # in your list data <- list(...) # This line simply counts the # number of components in the # list variable 'data' that you # created in the line above. So # 'n' will be equal to the number # of input vectors that were passed # into the df.maker2() function at # the very top. n <- length(data) # < you put some code in here > if(n > 2) { # < you put some code in here > # < you put some code in here > } else # < you put code in here > # < you put code in here > # < you put code in here > }

# Please follow these specific directions: # (7) Use these specific vectors as # input for data.maker2() so read # them into your session first: x <- c(2,3,4,5,6);x y <- as.logical(c(T,F,T,F,F));y z <- c('a','b','c','d','e');z a <- c(1.2,4.5,3,8.7,0);a

# Test it out with this: df.maker2(x,y,a,z) # for example # should output this exactly: # x y a z # 1 2 TRUE 1.2 a # 2 3 FALSE 4.5 b # 3 4 TRUE 3 c # 4 5 FALSE 8.7 d # 5 6 FALSE 0 e

# Test it out with this (only one input vector): df.maker2(x) # could output this, # but the output will vary each time # in the number of vectors output # but will always consist of from 2 to 9 # vectors of random modes generated by # the vector.maker() function inside # your df.maker2() function:

# X1 X2 X3 X4 X5 X6 X7 # 1 TRUE r x k e TRUE 72 # 2 FALSE g d o m TRUE 27 # 3 TRUE t v c j TRUE 13 # 4 TRUE a u v a FALSE 16 # 5 FALSE h a r c FALSE 30

# Test it out with this (no input vector): df.maker2() # no argument in the call # to your df.maker2() function could output this, # but the output will vary each time # and always consist of from 2 to 9 # vectors generated by vector.maker() # inside your df.maker2() function:

# X1 X2 X3 X4 X5 X6 X7 X8 # 1 FALSE TRUE o 78 9 50 a b # 2 TRUE FALSE t 48 74 17 j v # 3 FALSE FALSE m 76 31 93 z q # 4 TRUE TRUE q 59 55 45 r e # 5 TRUE FALSE j 36 62 90 c j

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 General Management Questions!