1. Write code to create a vector called numbers containing the numbers 1, 2, 3, 4, 5. Then,
perform each of the following tasks on separate lines in your R script:
o Add 10 to each element in the numbers vector. Store the result in a new variable
called numbers2 (hint: you can directly perform addition on the vector.)
• Multiply each element in the numbers2 vector by 2. Store the result in a new
variable called numbers3 (hint: you can directly perform multiplication on the
vector.)
Ο
Find the sum of all the numbers in the numbers3 vector. Store the result in a new
variable called total_sum
2. Create the following data frame in R, store the data frame in a variable called
sales data
sales_data
product price units_sold
Laptop 1200
50
Smartphone 800
200
150
Tablet 400
3. Using the sales_data data frame created in Question 2, perform each of the following
tasks on separate lines in your R script:
Extract the price column.
Extract the row for "Smartphone".
Filter the data to retain only the records where the price is greater than or equal to
800. (you must filter the data frame with a logical condition).
Filter the data to retain only the records where the price is greater than or equal to
800 AND the units sold is greater than 100.
4. Write an if-else statement that checks if a number x is greater than 10. If it is, print
"Greater than 10", and if it's not, print "Less than or equal to 10".