| irtc_read | R Documentation |
Unified data import with automatic cleaning. Supports Excel
(.xlsx, .xls; requires readxl), delimited text
(.csv, .tsv, .txt, .dat; delimiter and
UTF-8/GBK encoding are detected automatically), SPSS/Stata/SAS files
(.sav, .por, .dta, .sas7bdat, .xpt;
requires haven) and in-memory data frames, matrices and tibbles.
Every cleaning action is recorded in a bilingual log attached to the returned object, so results remain traceable.
irtc_read(x, sheet = 1, id = NULL, weights = NULL,
missing_codes = c(-9, -99, 99, 999),
na_strings = c("", "NA", "N/A", "n/a", ".", "*",
"\u7f3a\u5931", "\u65e0", "\u7a7a"),
guess_id = TRUE, guess_weights = TRUE, clean = TRUE, recode = TRUE,
verbose = TRUE)
## S3 method for class 'irtc_data'
print(x, lang = irtc_lang(), ...)
x |
A file path or a data frame / matrix. For the print method: an
|
sheet |
Excel sheet to read (number or name). |
id |
Person identifier column(s), by name or index. The first is kept
as the person ID; the rest are set aside. If |
missing_codes |
Numeric codes recoded to |
na_strings |
Strings treated as missing in text columns. |
weights |
Sampling weight column, by name or index. If |
guess_id |
Logical: detect the person ID column automatically? |
guess_weights |
Logical: detect the weight column automatically? |
clean |
Logical: apply the cleaning steps (drop empty rows/columns, convert numeric-like text, recode missing codes)? |
recode |
Logical: recode integer response categories to consecutive scores starting at 0 (e.g. a 1-5 Likert item becomes 0-4)? |
verbose |
Logical: print the object (including the cleaning log)? |
lang |
Output language, |
... |
Ignored. |
An object of class irtc_data: a list with components resp
(cleaned response data frame), pid (person IDs or NULL),
weights (sampling weights or NULL), dropped
(set-aside non-response columns), log (cleaning log
data frame with columns step, code, message_en,
message_zh) and source.
irtc, irtc_score,
irtc_check_data
path <- tempfile(fileext = ".csv")
writeLines(c("id,i1,i2,i3", "s1,0,1,99", "s2,1,-9,1", "s3,1,0,0"), path)
d <- irtc_read(path, verbose = FALSE)
d$resp
d$pid
print(d, lang = "en")
unlink(path)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.