0
0
R Programmingprogramming~15 mins

Data frame creation in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Data frame creation
📖 Scenario: You are working as a data analyst and need to organize some survey data into a table format for easy analysis.
🎯 Goal: Create a data frame in R with specific columns and data, then display it.
📋 What You'll Learn
Create a data frame with exact column names and values
Add a variable for the number of rows
Use the data.frame() function to create the data frame
Print the data frame to show the result
💡 Why This Matters
🌍 Real World
Data frames are used to organize and analyze data collected from surveys, experiments, or business records.
💼 Career
Knowing how to create and manipulate data frames is essential for data analysts, statisticians, and anyone working with data in R.
Progress0 / 4 steps
1
Create vectors for survey data
Create three vectors called names, ages, and cities with these exact values: names = c("Alice", "Bob", "Charlie"), ages = c(25, 30, 35), cities = c("New York", "Los Angeles", "Chicago")
R Programming
Need a hint?

Use the c() function to create vectors with the exact values given.

2
Create a variable for number of rows
Create a variable called num_rows that stores the number of elements in the names vector using the length() function
R Programming
Need a hint?

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

3
Create the data frame
Create a data frame called survey_data using the data.frame() function with columns Name, Age, and City using the vectors names, ages, and cities respectively
R Programming
Need a hint?

Use data.frame(Name = names, Age = ages, City = cities) to create the data frame with correct column names.

4
Print the data frame
Use print() to display the survey_data data frame
R Programming
Need a hint?

Use print(survey_data) to show the data frame in the console.