0
0
R Programmingprogramming~15 mins

Why vectors are the fundamental data structure in R Programming - See It in Action

Choose your learning style9 modes available
Why vectors are the fundamental data structure
📖 Scenario: Imagine you are organizing a list of your favorite fruits. You want to store them in a simple way so you can easily add, remove, or check your fruits. In R, vectors are the best way to do this because they hold elements of the same type in a single container.
🎯 Goal: You will create a vector of fruits, add a new fruit, check the length of the vector, and print the final list. This will show why vectors are the fundamental data structure in R.
📋 What You'll Learn
Create a vector called fruits with the exact values "apple", "banana", and "cherry"
Create a variable called new_fruit and set it to "orange"
Add new_fruit to the fruits vector using the c() function
Print the length of the fruits vector using the length() function
Print the fruits vector to show all fruits
💡 Why This Matters
🌍 Real World
Vectors are used in data analysis, statistics, and many R programs to store lists of values like measurements, names, or categories.
💼 Career
Understanding vectors is essential for data scientists, statisticians, and anyone working with R because almost all data starts as vectors.
Progress0 / 4 steps
1
Create the initial vector of fruits
Create a vector called fruits with these exact values: "apple", "banana", and "cherry" using the c() function.
R Programming
Need a hint?

Use c() to combine values into a vector.

2
Add a new fruit variable
Create a variable called new_fruit and set it to the string "orange".
R Programming
Need a hint?

Assign the string "orange" to new_fruit using <-.

3
Add the new fruit to the fruits vector
Add the new_fruit to the fruits vector by combining them with the c() function and assign the result back to fruits.
R Programming
Need a hint?

Use c(fruits, new_fruit) to add the new fruit to the vector.

4
Print the length and contents of the fruits vector
Print the length of the fruits vector using length(fruits). Then print the fruits vector itself.
R Programming
Need a hint?

Use print() to show the length and the vector.