read.xlsx | R Documentation |
This function calls the read_xlsx()
function in the readxl package
by Hadley Wickham and Jennifer Bryan (2019) to read an Excel file (.xlsx).
read.xlsx(file, sheet = NULL, header = TRUE, range = NULL,
coltypes = c("skip", "guess", "logical", "numeric", "date", "text", "list"),
na = "", trim = TRUE, skip = 0, nmax = Inf, guessmax = min(1000, nmax),
progress = readxl::readxl_progress(), name.repair = "unique",
as.data.frame = TRUE, check = TRUE)
file |
a character string indicating the name of the Excel data
file with or without file extension '.xlsx', e.g., |
sheet |
a character string indicating the name of a sheet or a numeric value indicating the position of the sheet to read. By default the first sheet will be read. |
header |
logical: if |
range |
a character string indicating the cell range to read from,
e.g. typical Excel ranges like |
coltypes |
a character vector containing one entry per column from
these options |
na |
a character vector indicating strings to interpret as missing values. By default, blank cells will be treated as missing data. |
trim |
logical: if |
skip |
a numeric value indicating the minimum number of rows to
skip before reading anything, be it column names or data.
Leading empty rows are automatically skipped, so this is
a lower bound. Ignored if the argument |
nmax |
a numeric value indicating the maximum number of data rows
to read. Trailing empty rows are automatically skipped, so
this is an upper bound on the number of rows in the returned
data frame. Ignored if the argument |
guessmax |
a numeric value indicating the maximum number of data rows to use for guessing column types. |
progress |
display a progress spinner? By default, the spinner appears only in an interactive session, outside the context of knitting a document, and when the call is likely to run for several seconds or more. |
name.repair |
a character string indicating the handling of column names. By default, the function ensures column names are not empty and are unique. |
as.data.frame |
logical: if |
check |
logical: if |
Returns a data frame or tibble.
Hadley Wickham and Jennifer Bryan
Wickham H, Miller E, Smith D (2023). readxl: Read Excel Files. R package version 1.4.3. https://CRAN.R-project.org/package=readxl
read.dta
, write.dta
, read.sav
,
write.sav
, read.mplus
, write.mplus
## Not run:
# Example 1: Read Excel file (.xlsx)
read.xlsx("data.xlsx")
# Example 1: Read Excel file (.xlsx), use default names as column names
read.xlsx("data.xlsx", header = FALSE)
# Example 2: Read Excel file (.xlsx), interpret -99 as missing values
read.xlsx("data.xlsx", na = "-99")
# Example 3: Read Excel file (.xlsx), use x1, x2, and x3 as column names
read.xlsx("data.xlsx", header = c("x1", "x2", "x3"))
# Example 4: Read Excel file (.xlsx), read cells A1:B5
read.xlsx("data.xlsx", range = "A1:B5")
# Example 5: Read Excel file (.xlsx), skip 2 rows before reading data
read.xlsx("data.xlsx", skip = 2)
# Example 5: Read Excel file (.xlsx), return a tibble
read.xlsx("data.xlsx", as.data.frame = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.