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
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)
Get Answers For Free
Most questions answered within 1 hours.