Load Tidyverse Package and Write a Function - Computer Science Assignment Help

Download Solution Order New Solution
Assignment Task :

Q1)
Load tidyverse package and write a function that will take a dataframe/tibble as an argument and a factor variable as another argument and will create dummy variable for that factor and append them to the end for the dataframe. Call the function create_dummies() You cannot use the ‘model.matrix()’ function or any packages that might actually do this, you must do it from scratch. Make sure you deal with cases where someone doesn’t put in a tibble/dataframe as first argument and a factor as second argment. also include a third argument where the user can decide whether or not they want to drop the original variable and just keep the dummies or keep all three. Make this third argument have a default value of TRUE. The tibble you return should only include the original variable (if third argument is TRUE) and the dummies, not any other variables in the data.
If you are not aware, a dummy variable is a variable that can either be true (1) or can be false (0). It cannot take on any other value

Q2) 
The create_dummies() function is great it will take a single factor variable and will return the dummy variables we want. But what if we have 20 or 30 or 100 variables we want to create dummies for. Then we have to run this function 20, 30, or 100 times. That seems really inefficeint. Wrtie a new function called create_multiple_dummies() that will take a dataframe/tibble as the first argument, and the second argument should be a vector of variable names that we want this to operate on. This function should run the create_dummies() function you just wrote on each variable in the vector of variables names. Finally it should bind all these together and return the finished tibble. Use the tibble created on test  to do this, you should use the functions from the purrr package to make this happen.

Q3)
Finally we may want our users to be able to specify that they want to keep some of the original variables and discard others, so re-write the create_multiple_dummies() function and call it create_multiple_dummies2. It will take all the same arguments as the original function but it will also take a fourth argument called .keeps which is a vector of TRUE/FALSE that correspond to each varaible specified and should have a default value of NULL. For example if we want to keep ‘age’ but discard ‘income’ and ‘sex’ then we should be able to call the function like this create_multiple_dummies2(df, c('sex', 'age', 'income'), .keeps = c(F, T, F))
 

 

This Computer Science Assignment has been solved by our Computer Science  Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.

Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.