Question

Use Rstudio to create a script by following the instruction below. I've created the first question...

Use Rstudio to create a script by following the instruction below.

I've created the first question code but I can not continue it further. Thank you.

## Write a function called `make_introduction` that takes in two arguments: name, and age.
## This function should return a string value that says something like "Hello, my name is {name}, and I'm
## {age} years old".
make_introduction <- function(name, age){
print(paste("Hello, my name is", name, "and I'm", age, "years old"))
}

## Create a variable `my_intro` by passing your variables `my_name` and `my_age` into your `make_introduction`
## function. Always print the result!

## Create a variable `casual_intro` by substituting "Hello, my name is ", with "Hey, I'm" in your `my_intro`
## variable. Check out base R functions 'sub' and 'gsub', and stringr functions 'str_replace' and 'str_replace_all'


## Create a new variable `loud_intro`, which is your `my_intro` variable in all upper-case letters


## Create a new variable `quiet_intro`, which is your `my_intro` variable in all lower-case letters


## Create a new variable capitalized, which is your `my_intro` variable with each word capitalized
## hint: consult the stringr function `str_to_title`


## Using the `str_count` function, create a variable `occurrences` that stores the # of times the letter "e"
## appears in `my_intro`


## Write another function `double` that takes in a (numeric) variable and returns that variable times two


## Using your `double` function, create a variable `minutes_in_two_days`, which is the number of minutes in
## two days


## Write another function `third_power` that takes in a value and returns that value cubed


## Create a variable `twenty_seven`` by passing the number 3 to your `cube` function

Homework Answers

Answer #1

library(stringr)
## Write a function called `make_introduction` that takes in two arguments: name, and age.
## This function should return a string value that says something like "Hello, my name is {name}, and I'm
## {age} years old".
make_introduction <- function(name, age){
return (sprintf("Hello, my name is %s, and I'm %d years old",name,age))#edited the function to return a string
}

## Create a variable `my_intro` by passing your variables `my_name` and `my_age` into your `make_introduction`
## function. Always print the result!
my_intro=make_introduction("YourName",19)#enter name and age
print(my_intro)

## Create a variable `casual_intro` by substituting "Hello, my name is ", with "Hey, I'm" in your `my_intro`
## variable. Check out base R functions 'sub' and 'gsub', and stringr functions 'str_replace' and 'str_replace_all'
casual_intro=sub("Hello, my name is","Hey, I'm",my_intro)
print(casual_intro)

## Create a new variable `loud_intro`, which is your `my_intro` variable in all upper-case letters
loud_intro = toupper(my_intro)
print(loud_intro)

## Create a new variable `quiet_intro`, which is your `my_intro` variable in all lower-case letters
loud_intro = tolower(my_intro)
print(loud_intro)

## Create a new variable capitalized, which is your `my_intro` variable with each word capitalized
## hint: consult the stringr function `str_to_title`
capitalized = str_to_title(my_intro)
print(capitalized)

## Using the `str_count` function, create a variable `occurrences` that stores the # of times the letter "e"
## appears in `my_intro`
occurrences=str_count(my_intro,"e")
print(occurrences)

## Write another function `double` that takes in a (numeric) variable and returns that variable times two
double <- function(num){
return (2*num)
}

## Using your `double` function, create a variable `minutes_in_two_days`, which is the number of minutes in
## two days
minutes_in_two_days = double(24*60)
print(minutes_in_two_days)


## Write another function `third_power` that takes in a value and returns that value cubed
third_power <- function(num){
return (num^3)
}

## Create a variable `twenty_seven`` by passing the number 3 to your `cube` function
twenty_seven=third_power(3)
print(twenty_seven)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Programming Build a python programming that asks the user for a three-letter substring. The program...
Python Programming Build a python programming that asks the user for a three-letter substring. The program should then proceed to read the file strings.txt. Each line in strings.txt will contain a string. Your program should then test to see how many non-overlapping occurrences of the three-letter substring occur in that string and test whether the string is a palindrome. The program should then proceed to create an output file string_stats.txt, which contains the original data on one line and the...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
C++ code This project uses the text file (patient.dat) containing the following data: Patient number      ...
C++ code This project uses the text file (patient.dat) containing the following data: Patient number       integer Patient last name    string Patient surgery        string Patient age               integer Create a menu driven C++ project containing a user defined class with public functions that do the following: Read in all data into a linked list Display a menu for the user selections Add another set of patient data Print all data in the linked list Print all patients who...
java Create a program that defines a class called circle. Circle should have a member variable...
java Create a program that defines a class called circle. Circle should have a member variable called radius that is used to store the radius of the circle. Circle should also have a member method called calcArea that calculates the area of the circle using the formula area = pi*r^2. Area should NOT be stored in a member variable of circle to avoid stale data. Use the value 3.14 for PI. For now, make radius public and access it directly...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half of the code but I am using else and if statements. I feel like the code is too long to do a simple calculation. In CodeBlock when you build and run your code, a new terminal window opens (in windows a new console window) and you can enter your inputs there. It is not like eclipse that you enter your inputs in console view....
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT