04_Data_Import_Export Flashcards

(7 cards)

1
Q

Front

A

Back

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you read a CSV with readr::read_csv() and control types?

A

Use read_csv(file, col_types=) to enforce types and na strings.

Code:
library(readr)
df <- read_csv(‘data.csv’, col_types = cols(
id = col_integer(),
date = col_date(),
value = col_double()
), na = c(‘’, ‘NA’, ‘NULL’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you read tab-delimited or arbitrary-delimited files?

A

Use read_tsv() or read_delim(delim = ‘;’).

Code:
library(readr)
read_tsv(‘data.tsv’)
read_delim(‘euro.csv’, delim=’;’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you import Excel files?

A

Use readxl::read_excel() (no Java needed).

Code:
library(readxl)
df <- read_excel(‘workbook.xlsx’, sheet = ‘Sheet1’, range = NULL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you save and load R objects efficiently?

A

Use saveRDS()/readRDS() for single objects.

Code:
saveRDS(model, file = ‘model.rds’)
model <- readRDS(‘model.rds’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you write CSV output with readr?

A

Use write_csv() for UTF-8, fast writing.

Code:
library(readr)
write_csv(df, ‘clean_data.csv’, na = ‘’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you skim a file before full import?

A

Use readr::read_lines() or vroom::vroom() for quick previews.

Code:
library(readr)
read_lines(‘data.csv’, n_max = 5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly