The “read.csv” Function in R
Package: Base R (utils package)
Purpose: To read a comma-separated values (CSV) file into a data frame.
General Class: Input/Output
Required Argument(s):
file: A connection or a character string giving the name of the file to read from.
Notable Optional Arguments:
header: A logical value indicating whether the file has a header line with column names (default is TRUE).
sep: The field separator character (default is ,).
quote: The quoting character (default is ").
Example:
# Example usage
# Assume a CSV file named "data.csv" with header
# Read the CSV file into a data frame
df <- read.csv("data.csv")
# Print the structure of the data frame
str(df)In this example, the read.csv function is used to read a CSV file named “data.csv” into a data frame (df). The resulting data frame is then printed using the str function to display its structure.