R Lesson 3: Reading CSV and Excel

R Lesson 3: Reading CSV and Excel featured illustration

πŸ“Ž This article includes 2 downloadable practice files ↓

⏱ 1 min read

πŸ“˜ R Beginner Course Β· Lesson 3 of 6

Advertisement
library(readr)
sales <- read_csv("sales.csv")
head(sales); nrow(sales); summary(sales$qty)
library(readxl)
x <- read_excel("file.xlsx", sheet = "Data")
write_csv(sales, "sales_copy.csv")

read_csv shows the type it guessed for each column; fix wrong guesses with col_types. Missing values are NA; most functions need na.rm = TRUE to ignore them (e.g. mean(x, na.rm = TRUE)).

πŸ’‘ For dd-mm-yyyy dates use lubridate::dmy(); for yyyy-mm-dd use ymd().

Code for this course follows standard, current syntax; we test JavaScript and PowerShell scripts before publishing, and R/Java/Rust examples are kept to core language features. Tell us if anything fails on your setup.

Practice

Read sales.csv and check its structure.

Advertisement

πŸ“Ž Practice files for this article

⬇ Download all 2 files (ZIP Β· 662 B)

Free to use for learning. Files with macros (.bas) are plain text β€” import them with Alt+F11 β†’ File β†’ Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free Β· AI can be wrong