Question
Using R Programming Language Part 1: Introduction to modeling using basic R syntax Congratulations, you have puppy fever! As someone who is inflicted with puppy
Using R Programming Language
Part 1: Introduction to modeling using basic R syntax
Congratulations, you have puppy fever! As someone who is inflicted with puppy fever, you would like to buy as many puppies as you perceivably can. To help you determine if you can afford all of the puppies you want or to determine how many puppies you can afford, you opt to use R to help you. In this exercise, please print the contents of each variable after you declare it.
-
Create a variable puppies equal to the number of puppies youd like to have.
-
Create a variable puppy_price, which is how much you think a puppy costs.
-
Create a variable total_cost that has the total cost of all of your puppies.
-
Create a boolean variable too_expensive, set to TRUE if the cost is greater than $1,000.
-
Create a variable max_puppies, which is the number of puppies you can afford for $1,000.
Part 2: Manipulating variables and learning how to use new functions
You work as a data analyst for a new company and are asked to create id tags for everyone at work. Your goal is to make it informative as well as personal to help facilitate collaboration in the work place. To do this, you first want to gather information about each employee.
-
Assign your name to the variable my_name in four different ways.
-
Assign your height (in inches) to a variable my_height.
-
Assign your favorite day to a varialbe favorite_day as a date object.
-
Assign your favorite quote to a variable favorite_quote. How many characters does your favorite quote have?
-
Show what type of objects my_name, my_height, favorite_day, and favorite_quote are.
-
Coerce these variables to numerics and describe what happens.
-
Create a vector variable named id that contains my_name, my_height, favorite_day, and favorite_quote.
-
What class is id? Did the classes for my_name, my_height, favorite_day, and favorite_quote change when they were stored in id? Did the classes change for the variables themselves?
Your employer wants you to be able to print each employees id while displaying each variable of information line by line. As a beginner with R, however, you are unfamiliar with how to do this so your employer gives you a hint to use the functions cat and paste.
-
Try using cat and paste with id as a function argument. How do the results differ? What happens when we use cat and paste at the same time (i.e. f(g(x)))? What happens if we change the order we use them (i.e. g(f(x)))?
-
How would you determine the difference between cat and paste using R documentation (from within RStudio)? What is a great internet resource to use as discussed in the book?
-
What do sep and collapse arguments for paste do? If we wanted to append each character variable in our vector id with a new line (i.e. " ") would we use sep or collapse?
-
Display the contents of id using a combination of cat and paste with the appropriate arguments for paste.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started