Introduction
Data frames help organize data in rows and columns, making it easy to work with tables of information in R.
Data frames help organize data in rows and columns, making it easy to work with tables of information in R.
data_frame_name <- data.frame(column1 = c(values), column2 = c(values), ...)
df <- data.frame(Name = c("Anna", "Ben"), Age = c(25, 30))
df$Age
# Access the Age column from the data framenrow() and ncol() to find how many rows and columns the data frame has.nrow(df) ncol(df)
This program creates a data frame with three people and their ages and scores. It prints the whole table, the number of rows and columns, and Bob's score.
df <- data.frame(Name = c("Alice", "Bob", "Carol"), Age = c(28, 34, 23), Score = c(85, 90, 88)) print(df) print(paste("Number of rows:", nrow(df))) print(paste("Number of columns:", ncol(df))) print(paste("Bob's score:", df$Score[2]))
Data frames are easy to read and understand because they look like tables.
They are the main way to store and work with data in R, especially for statistics and data analysis.
Data frames organize data in rows and columns, like a spreadsheet.
They allow different types of data in each column.
Data frames are essential for analyzing and managing data in R.
df <- data.frame(name = c('Tom', 'Sue'), age = c(22, 28))
str(df)df <- data.frame(name = c('Amy', 'John'), age = c(30, 'twenty'))Pass the test and this pattern moves unknown