library(knitr)
knit("4. readr.Rmd")
## 
## 
## processing file: 4. readr.Rmd
## 
  |                                                       
  |                                                 |   0%
  |                                                       
  |...                                              |   6%                   
  |                                                       
  |......                                           |  12% [unnamed-chunk-29]
  |                                                       
  |.........                                        |  18%                   
  |                                                       
  |............                                     |  24% [unnamed-chunk-30]
  |                                                       
  |..............                                   |  29% [unnamed-chunk-31]
  |                                                       
  |.................                                |  35%                   
  |                                                       
  |....................                             |  41% [unnamed-chunk-32]
  |                                                       
  |.......................                          |  47%                   
  |                                                       
  |..........................                       |  53% [unnamed-chunk-33]
  |                                                       
  |.............................                    |  59%                   
  |                                                       
  |................................                 |  65% [unnamed-chunk-34]
  |                                                       
  |...................................              |  71%                   
  |                                                       
  |.....................................            |  76% [unnamed-chunk-35]
  |                                                       
  |........................................         |  82%                   
  |                                                       
  |...........................................      |  88% [unnamed-chunk-36]
  |                                                       
  |..............................................   |  94%                   
  |                                                       
  |.................................................| 100% [unnamed-chunk-37]
## output file: 4. readr.md
## [1] "4. readr.md"
#link: https://drive.google.com/drive/folders/1H2naIYxR58SwxsR34TPuC6cQkJMdFIK0?usp=sharing
#database: mtcars.csv, titanic.xlsx

#install.packages("readxl")
#library(readxl)
#library(readr)
# Đọc tập tin CSV và lưu vào một biến dữ liệu
csv_mtcars <- read_csv("databases/mtcars.csv")
## Rows: 32 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────
## Delimiter: ","
## dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Hiển thị một số dòng đầu của dữ liệu
head(mtcars)
# Đọc tập tin CSV mà không sử dụng dòng header và lưu vào một biến dữ liệu
csv_mtcars_no_header <- read_csv("databases/mtcars.csv", col_names = FALSE)
## Rows: 33 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Hiển thị một số dòng đầu của dữ liệu
head(csv_mtcars_no_header)
# Đọc tập tin Excel và lưu vào một biến dữ liệu
excel_titanic <- read_excel("databases/titanic.xlsx")

# Hiển thị một số dòng đầu của dữ liệu
head(excel_titanic)
# Đọc tập tin TXT với ngăn cách bằng tab và lưu vào một biến dữ liệu
tab_peoples <- read_tsv("databases/peoples.txt")
## Rows: 3 Columns: 1
## ── Column specification ──────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (1): Name    Age   City
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Hiển thị một số dòng đầu của dữ liệu
head(tab_peoples)
# Đọc tập tin với ngăn cách tùy chỉnh và lưu vào một biến dữ liệu
custom_delim_data <- read_delim("databases/delim.txt", delim = "|")
## Rows: 3 Columns: 3
## ── Column specification ──────────────────────────────────────────────────────
## Delimiter: "|"
## chr (2): Name, City
## dbl (1): Age
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Hiển thị dữ liệu
print(custom_delim_data)