0
0
R Programmingprogramming~15 mins

Why advanced features enable complex work in R Programming - See It in Action

Choose your learning style9 modes available
Why advanced features enable complex work
📖 Scenario: Imagine you are a data analyst working with a list of sales numbers. You want to understand which sales are above a certain target and calculate some statistics. Using R's advanced features like vectorized operations and functions can help you do this quickly and clearly.
🎯 Goal: You will create a vector of sales numbers, set a target value, use R's vectorized features to find sales above the target, and then print the count of those sales.
📋 What You'll Learn
Create a numeric vector called sales with these exact values: 120, 85, 90, 150, 200, 75
Create a numeric variable called target and set it to 100
Use R's vectorized comparison to create a logical vector above_target that is TRUE where sales are greater than target
Print the number of sales above the target using sum(above_target)
💡 Why This Matters
🌍 Real World
Data analysts often need to quickly find and summarize data points that meet certain conditions, like sales above a target.
💼 Career
Using vectorized operations and logical indexing in R is a key skill for data scientists and analysts to write efficient and readable code.
Progress0 / 4 steps
1
Create the sales vector
Create a numeric vector called sales with these exact values: 120, 85, 90, 150, 200, 75
R Programming
Need a hint?

Use the c() function to combine numbers into a vector.

2
Set the target value
Create a numeric variable called target and set it to 100
R Programming
Need a hint?

Assign the number 100 to the variable target using <-.

3
Find sales above the target
Use R's vectorized comparison to create a logical vector called above_target that is TRUE where sales are greater than target
R Programming
Need a hint?

Use the > operator to compare each element of sales to target.

4
Print the count of sales above target
Print the number of sales above the target using print(sum(above_target))
R Programming
Need a hint?

Use sum() to count TRUE values in above_target, then print the result.