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