0% found this document useful (0 votes)
6 views2 pages

Reading Data Files in R: CSV, TXT, Excel

The document provides instructions on reading various file formats in R, including CSV, text, and Excel files. It outlines the syntax for reading these files, including options for custom separators and reading specific sheets in Excel. Additionally, it includes commands for viewing data in R.

Uploaded by

smaran05102005s
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Reading Data Files in R: CSV, TXT, Excel

The document provides instructions on reading various file formats in R, including CSV, text, and Excel files. It outlines the syntax for reading these files, including options for custom separators and reading specific sheets in Excel. Additionally, it includes commands for viewing data in R.

Uploaded by

smaran05102005s
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Reading Data from Files in R

1. READING CSV FILES:

CSV (Comma Separated Values) is a common format for storing data.

Syntax:

data <- [Link]("[Link]")

Example:

students <- [Link]("[Link]")

With Custom Separator:

data <- [Link]("[Link]", sep = ",")

---------------------------------------------

2. READING TEXT FILES:

Text files can be space-separated or tab-separated.

Syntax:

data <- [Link]("[Link]", header = TRUE)

With Tab Separator:

data <- [Link]("[Link]", sep = "\t", header = TRUE)

---------------------------------------------
3. READING EXCEL FILES (.xlsx or .xls):

Use 'readxl' package to read Excel files.

Installation:

[Link]("readxl")

Loading and Reading:

library(readxl)

data <- read_excel("[Link]")

Reading Specific Sheet:

data <- read_excel("[Link]", sheet = "Sheet2")

---------------------------------------------

4. VIEWING DATA:

head(data) # Shows first 6 rows

tail(data) # Shows last 6 rows

View(data) # Opens data viewer in RStudio

You might also like