1.加载 readxl 包,利用 reade_excel() 函数
install.packages("readxl") library(readxl) data = read_excel("22_data.xlsx",sheet = 1)
read_excel函数的参数设置:
用法:
read.xlsx(xlsxFile, sheet = 1, startRow = 1, colNames = TRUE,
rowNames = FALSE, detectDates = FALSE, skipEmptyRows = TRUE,
skipEmptyCols = TRUE, rows = NULL, cols = NULL, check.names = FALSE,
namedRegion = NULL, na.strings = "NA", fillMergedCells = FALSE)
参数:
startRow :从这一行开始查找数据,无论startRow是多少,文件上面的空行都会被跳过
colNames :如果为真,第一行的数据就是列的名字
rowNames :如果为真,第一类数据会被作为行的名字
detectDates :如果为真,则尝试识别日期并进行转换
skipEmptyRows 如果为真,会跳过空行,如果第一个有数据行之后有空行则返回一行NAs
If TRUE, empty rows are skipped else empty rows after the first row containing data will return a row of NAs.
skipEmptyCols 如果为真,会跳过空列
If TRUE, empty columns are skipped.
rows 如果为空则读所有的行,否则输入一个向量来读取向量对应的行。
cols
A numeric vector specifying which columns in the Excel file to read. If NULL, all columns are read.
check.names
logical. If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names
namedRegion
A named region in the Workbook. If not NULL startRow, rows and cols parameters are ignored.
na.strings
A character vector of strings which are to be interpreted as NA. Blank cells will be returned as NA.
fillMergedCells
If TRUE, the value in a merged cell is given to all cells within the merge.
注意:此函数既可以读 .xls 也可以读.xlsx 类型文件
2.加载 openxlsx 包,利用 read.xlsx() 函数
install.packages("openxlsx") library(xlsx) read.xlsx("22_data.xlsx",sheet=1)
注意:此函数仅可以读取 .xlsx 类型文件
原文:https://www.cnblogs.com/jiaxinwei/p/11520923.html