安装库

install.packages("readxl")

调用

library(readxl)
read_excel(path, sheet = NULL, range = NULL, col_names = TRUE,
  col_types = NULL, na = "", trim_ws = TRUE, skip = 0,
  n_max = Inf, guess_max = min(1000, n_max),
  progress = readxl_progress(), .name_repair = "unique")

read_xls(path, sheet = NULL, range = NULL, col_names = TRUE,
  col_types = NULL, na = "", trim_ws = TRUE, skip = 0,
  n_max = Inf, guess_max = min(1000, n_max),
  progress = readxl_progress(), .name_repair = "unique")

read_xlsx(path, sheet = NULL, range = NULL, col_names = TRUE,
  col_types = NULL, na = "", trim_ws = TRUE, skip = 0,
  n_max = Inf, guess_max = min(1000, n_max),
  progress = readxl_progress(), .name_repair = "unique")

随便构造的数据
在这里插入图片描述
在这里插入图片描述

library(readxl)
df <- read_excel("C:/df.xlsx")
df

在这里插入图片描述
按位置或名称指定工作表

df_2 <- read_excel("C:/df.xlsx", sheet ='数据')
#df_2 <- read_excel("C:/df.xlsx", sheet =2)
df_2

在这里插入图片描述
跳过行并使用默认列名

#跳过前2行
df_3 <- read_excel("C:/df.xlsx", sheet ='数据',skip = 3,col_names = F)
df_3

在这里插入图片描述
使用A1或B1、C1等符号从Excel区域读取
在这里插入图片描述

df_4 <- read_excel("C:/df.xlsx", range = "A3:C6", col_names = FALSE)
df_4

在这里插入图片描述

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐