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,
use.value.labels = FALSE, use.missings = TRUE, na.strings = "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. |
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
read.sav
, read.xlsx
, read.dta
,
read.mplus
## Not run:
# Read CSV data file
dat <- read.data("CSV_Data.csv")
# Read DAT data file
dat <- read.data("DAT_Data.dat")
# Read TXT data file
dat <- read.data("TXT_Data.txt")
# Read SPSS data file
dat <- read.data("SPSS_Data.sav")
# Read Excel data file
dat <- read.data("Excel_Data.xlsx")
# 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.