| read.data | R Documentation |
This function reads a (1) data file in CSV (.csv), DAT (.dat),
or TXT (.txt) format using the fread function from the data.table
package, (2) SPSS file (.sav) using the read.sav function, (3)
Excel file (.xlsx) using the read.xlsx function, or a (4) Stata
DTA file (.dta) using the read.dta function in the misty
package.
read.data(file, sheet = NULL, header = TRUE, select = NULL, drop = NULL,
sep = "auto", dec = "auto", use.value.labels = FALSE,
use.missings = TRUE, na.strings = c("NA", ""),
stringsAsFactors = FALSE, formats = FALSE, label = FALSE,
labels = FALSE, missing = FALSE, widths = FALSE, as.data.frame = TRUE,
encoding = c("unknown", "UTF-8", "Latin-1"), check = TRUE)
file |
a character string indicating the name of the data file
with the file extension |
sheet |
a character string indicating the name of a Excel sheet
or a numeric value indicating the position of the Excel
sheet to read. By default the first sheet will be read
when reading an Excel file ( |
header |
logical: if |
select |
a character vector of column names or numeric vector to
keep, drop the rest. See the help page of the
|
drop |
a character vector of column names or numeric vector to drop, keep the rest. |
sep |
a character string indicating the separator between
columns for the |
dec |
a character string indicating the decimal separator
for the |
use.value.labels |
logical: if |
use.missings |
logical: if |
na.strings |
a character vector of strings which are to be interpreted as NA values. |
stringsAsFactors |
logical: if |
formats |
logical: if |
label |
logical: if |
labels |
logical: if |
missing |
logical: if |
widths |
logical: if |
as.data.frame |
logical: if |
encoding |
a character string indicating the encoding, i.e.,
|
check |
logical: if |
Returns a data frame, tibble, or data table.
Takuya Yanagida
Barrett, T., Dowle, M., Srinivasan, A., Gorecki, J., Chirico, M., Hocking, T., & Schwendinger, B. (2024). data.table: Extension of 'data.frame'. R package version 1.16.0. https://CRAN.R-project.org/package=data.table
Wickham H, Miller E, Smith D (2023). haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files. R package version 2.5.3. https://CRAN.R-project.org/package=haven
write.data, read.sav,
write.sav, write.xlsx,
read.dta, write.dta, read.mplus,
write.mplus
## Not run:
# Example 1: Read CSV data file
dat <- read.data("CSV_Data.csv")
# Example 2: Read DAT data file
dat <- read.data("DAT_Data.dat")
# Example 3: Read TXT data file
dat <- read.data("TXT_Data.txt")
# Example 4: Read SPSS data file
dat <- read.data("SPSS_Data.sav")
# Example 5: Read Excel data file
dat <- read.data("Excel_Data.xlsx")
# Example 6: Read Stata data file
dat <- read.data("Stata_Data.dta")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.