0
0
R Programmingprogramming~15 mins

Character (string) type in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Character (string) Type in R
📖 Scenario: You are creating a simple program to store and display names of fruits. This will help you understand how to work with character (string) data in R.
🎯 Goal: Build a small R script that stores fruit names as strings, counts how many fruits are in the list, extracts a specific fruit, and prints the results.
📋 What You'll Learn
Create a character vector with exact fruit names
Create a variable to store the number of fruits
Extract a specific fruit from the vector
Print the number of fruits and the extracted fruit
💡 Why This Matters
🌍 Real World
Working with character data is common when handling names, labels, or any text information in data analysis or software.
💼 Career
Knowing how to store and manipulate strings is essential for data cleaning, reporting, and user interface programming.
Progress0 / 4 steps
1
Create a character vector of fruits
Create a character vector called fruits with these exact values: "apple", "banana", "cherry", "date", "elderberry".
R Programming
Need a hint?

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

2
Count the number of fruits
Create a variable called num_fruits that stores the number of elements in the fruits vector using the length() function.
R Programming
Need a hint?

Use length(fruits) to find how many fruits are in the vector.

3
Extract a specific fruit
Create a variable called second_fruit that stores the second fruit in the fruits vector using indexing.
R Programming
Need a hint?

Use square brackets [] to get the second item from the vector.

4
Print the results
Print the number of fruits using print(num_fruits) and print the second fruit using print(second_fruit).
R Programming
Need a hint?

Use print() to show the values on the screen.