Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn data.frame() Function | Data Frames
R Introduction

bookdata.frame() Function

The data.frame() function creates a data frame from vectors or lists. Each vector becomes a column, and its variable name is used as the column name.

Example

12345678
# Data name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") # Create a data frame test <- data.frame(name, age, gender) test
copy

The resulting data frame has three columns (name, age, and gender), with column names automatically taken from the variable names.

Task

Swipe to start coding

You have two vectors: items and prices, containing the names and prices of goods in a local furniture store.

Your tasks are to:

  1. Create a data frame named store with two columns, items and prices (these are the respective variable names).
  2. Output store variable value.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain what a data frame is used for in R?

How can I access a specific column or row in the data frame?

What happens if the vectors have different lengths?

close

Awesome!

Completion rate improved to 2.27

bookdata.frame() Function

Swipe to show menu

The data.frame() function creates a data frame from vectors or lists. Each vector becomes a column, and its variable name is used as the column name.

Example

12345678
# Data name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") # Create a data frame test <- data.frame(name, age, gender) test
copy

The resulting data frame has three columns (name, age, and gender), with column names automatically taken from the variable names.

Task

Swipe to start coding

You have two vectors: items and prices, containing the names and prices of goods in a local furniture store.

Your tasks are to:

  1. Create a data frame named store with two columns, items and prices (these are the respective variable names).
  2. Output store variable value.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 2
single

single

some-alt