read.csv() (R)
read.csv() loads a comma-separated values file into a data frame. It is the standard base-R way to import tabular data, with options for headers, separators, and type handling.
R
read.csv("file.csv") reads a CSV from disk (or a URL) and returns a data frame, treating the first row as column names by default (header = TRUE). It handles quoting and infers each column's type. Related functions read.table() (general delimited text) and read.delim() (tab-separated) cover other formats.
Common arguments tune the import: sep for a different delimiter, na.strings to mark which text counts as NA, stringsAsFactors (FALSE since R 4.0, so text stays character), and skip to ignore header lines. Always inspect the result with str() and head() to confirm types imported correctly.
For large files or tidyverse workflows, readr::read_csv() (returns a tibble, faster, better defaults) and data.table::fread() (very fast) are popular alternatives. But read.csv() remains the no-dependency baseline taught first.
Syntax
df <- read.csv("data.csv")
df <- read.csv("data.csv", stringsAsFactors = FALSE)Examples
R — read.csv returns a data frame; str() and head() reveal its structure.
# Read a CSV into a data frame
df <- read.csv("sales.csv")
# Inspect what came in
str(df)
head(df, 3)