R语言中利用readxl包读取excel数据

 

1、测试文件

 

 

 

 

2、加载readxl包、读取数据

> library(readxl)                                              ## 加载readxl包
> dir()
[1] "test.xlsx"
> sheet1 <- read_xlsx("test.xlsx", sheet = 1, col_names = F)   ## 利用read_xlsx函数读取文件, 读取sheet1    
New names:
• `` -> `...1`
• `` -> `...2`
> sheet1 <- as.data.frame(sheet1)
> sheet1
  ...1 ...2
1   aa  300
2   bb  400
3   cc  500
> sheet2 <- read_xlsx("test.xlsx", sheet = 2, col_names = F)    ## 读取sheet2
New names:
• `` -> `...1`
• `` -> `...2`
> sheet2 <- as.data.frame(sheet2)
> sheet2
  ...1 ...2
1 1000  xxx
2 3000  yyy
3 5533  zzz

 

posted @ 2022-05-08 22:27  小鲨鱼2018  阅读(1720)  评论(0编辑  收藏  举报