In: Computer Science
PLEASE ANSWER using R studio .
VARIABLE ASSIGNMENT AND SIMPLE FUNCTIONS ##
#########################################################
#Section 2 instructions:
#Answer the following questions by defining the provided
objects.
#Question 2.1 (2 points)
#Create a numeric vector that contains all integers between 1 and
1,000 (inclusive)
aS2Q1 <-
#Question 2.2 (2 points)
#Create a numeric vector that contains all even integers between 2
and 1,000 (inclusive)
aS2Q2 <-
#Question 2.3 (2 points)
#Four strings are defined as character vectors below. Using the
already defined
#character vectors, create a single character vector that combines
all of them
#and separates the contents of each with a comma followed by a
space.
str1 <- "The National Mall in Washington"
str2 <- "D.C. has monuments"
str3 <- "museums"
str4 <- "and scenery that draws many tourists from around the
world."
aS2Q3 <-
#Question 2.4 (2 points)
#Translate the following mathematical function into an R function
named "zFunction": z = (x + x^2 + x^3) - (y + y^2 + y^3)
#Then, evaluate for (x, y) = (3, 4) and save your answer to the
provided object.
zFunction <-
aS2Q4 <-
#Question 2.5 (2 points)
#Create a four-element list where each element is your answer to
questions 2.1-2.4.
#Name the four elements ans1, ans2, ans3, and ans4
aS2Q5 <-
#Question 2.6 (2 points)
#Display the element ans3 from the list created in question 2.5
using two different methods
Please give thumbs up to my answer, If you find it helpful.
#Question 2.1
aS2Q1 <- c(1:1000)

#Question 2.2
aS2Q2 <- seq(2,1000,2)

#Question 2.3
str1 <- "The National Mall in Washington"
str2 <- "D.C. has monuments"
str3 <- "museums"
str4 <- "and scenery that draws many tourists from around the
world."
aS2Q3 <-c(str1,str2,str3,str4)

#Question 2.4
zFunction <- function(x,y){
z=(x+x*x+x*x*x)-(y+y*y+y*y*y)
return(z)
}
aS2Q4 <- zFunction(3,4)

#Question 2.5
aS2Q5 <- list(ans1=aS2Q1, ans2=aS2Q2, ans3=aS2Q3,
ans4=aS2Q4)

#Question 2.6
aS2Q5['ans3']
