-
readxl包读取excel文件
2020-10-11 21:16:58虽然建议数据多用csv文件格式存贮,方便源代码直接查看,但很多excel数据文件可以方便地把多个数据文件集合在一个文件,减少了多文件转移过程中的错漏,R语言中可以加载readxl包实现对excel数据文件的访问,但是仍要...
虽然建议数据多用csv文件格式存贮,方便源代码直接查看,但很多excel数据文件可以方便地把多个数据文件集合在一个文件,减少了多文件转移过程中的错漏,R语言中可以加载readxl包实现对excel数据文件的访问,但是仍要尽可能符合tidy数据要求。主函数
read_excel
read_xls()
read_xlsx()
其中read_excel
会首先确定文件格式,因此如果知道文件后缀,建议直接调用对应的函数:
read_???(path,sheet,range,col_types)
实例
路径
# path and file names datasets <- readxl_example("datasets.xlsx") #获取实例excel文件路径 # show sheet names >excel_sheets(datasets) #显示excel文件中的sheet的名称 [1] "iris" "mtcars" "chickwts" "quakes"
读取worksheet
#read sheet read_excel(datasets) #default the 1st sheet read_excel(datasets, sheet=2) #读取第2个sheet read_excel(datasets, "mtcars") #读取名称为mtcars的sheet
选择性读取
# row skip read_excel(datasets,skip = 3) #跳过前3行 #specify row and col read_excel(datasets, range = cell_rows(3:6)) #读取第3-6行 read_excel(datasets, range = cell_cols("C:D")) #读取第3-4列 read_excel(datasets, range = cell_cols(2)) #读取第2列 #specify range read_excel(datasets, "mtcars",range="B2:D5") #读取特定区域 #读取从4行3列单元格为左上角直至底部的矩阵 read_excel(datasets, range = cell_limits(c(4, 3), c(NA, NA))) #读取从4行1列单元格为左上角直至底行4列的矩阵 read_excel(datasets, range = cell_limits(c(4, NA), c(NA, 4))) #读取以C4单元格为左上角开始的3行2列的矩阵数据 read_excel(datasets, range = anchored("C4", dim = c(3, 2)), col_names = FALSE)
-
将数据快速读入R—readr和readxl包
2017-12-01 18:02:06readxl包提供了一些在R中读入Excel电子表格数据的函数。它们的读取速度远远超过你目前正在用的一些函数。 readr包提供了若干函数在R中读取数据。我们通常会用R中的read.table家族函数来完成我们的数据读入Hadley Wickham 和 RStudio团队写了一些新的R包,这些包对于每个需要在R中读入数据的人来说都是非常有用的。readr包提供了一些在R中读入文本数据的函数。readxl包提供了一些在R中读入Excel电子表格数据的函数。它们的读取速度远远超过你目前正在用的一些函数。
readr
包提供了若干函数在R中读取数据。我们通常会用R中的read.table
家族函数来完成我们的数据读入任务。这里,readr
包提供了许多替代函数。它们增加了额外的一些功能并且速度快很多。首先,
read_table
几乎代替了read.table
。下面通过读取一个包含400万行的数据来比较它们的区别。点击这里下载该数据。注1:在演示之前简单说下我电脑的配置:win7,64位操作系统,8G内存,CPU A6双核。电脑配置不行,原文给出的实验时间甩了我好几条街。但不管怎样,在现有的条件下效率确实提高了很多。原文用时见末尾链接。
注2:如果读取中文数据出现乱码,在编辑器设置下字符编码为"UTF-8"
system.time(read_table("C:\\Users\\a\\Desktop\\biggerfile.txt", col_names=c("DAY","MONTH","YEAR","TEMP"))) system.time(read.table("C:\\Users\\a\\Desktop\\biggerfile.txt", col.names=c("DAY","MONTH","YEAR","TEMP")))
这些命令看上去非常相似,但是
read.table
花的时间是50.62秒,而read_table
完成相同的任务只花了2.76秒。这是因为read_table
把数据当做是固定格式的文件,并且使用C++快速处理数据。R中的基础包
utils
也有读取固定宽度数据的函数,下面的示例就能体现出readr
的亮点:system.time(read_fwf("C:\\Users\\a\\Desktop\\biggerfile.txt", fwf_widths(c(3,15,16,12), col_names=c("DAY","MONTH","YEAR","TEMP")))) system.time(read.fwf("C:\\Users\\a\\Desktop\\biggerfile.txt", c(3,15,16,12), col.ames=c("DAY","MONTH","YEAR","TEMP")))
readr
包的read_fwf
函数用时3.97秒,而标准的read.fwf
函数耗时1372秒。readr包中的其它函数包括:
read_csv
读取逗号分隔的数据(欧洲用的是read_csv2
函数),read_tsv
读取制表符分隔数据,read_lines
函数从文件中逐行读取数据(非常适合复杂的后期处理)。它还可以读取多种格式的日期时间列,智能的将文本数据读取为字符串(不再需要设置strings.as.factors=FALSE
)。对于Excel格式的数据,这里有readxl包。这个包提供的函数可以读取.xls和.xlsx格式的Excel工作表。虽然这里没有演示
read_execl
函数的使用,但是它跟readr
中的函数一样都是基于C++库的,因此读取速度应该也很快。最重要的是,它没有任何的外部依赖,因此你可以在任意平台上用它来读取数据—不要求安装了Excel。readr
包已发布在CRAN上,readxl
可以从github安装。本文由雪晴数据网负责翻译整理,原文请参考New packages for reading data into R — fast作者David Smith。转载请注明原文链接http://www.xueqing.tv/cms/article/102
-
R语言观察日志(part5)--利用readr和readxl包读写数据
2020-07-06 14:07:31利用readr和readxl包读写数据 读取数据 相关函数 函数包readr和readxl提供了一系列的数据读入功能,主要函数如下: #readr包 read_delim(file, delim, quote = "\"", escape_backslash = FALSE, escape_...学习笔记,仅供参考
利用readr和readxl包读写数据
读取数据
- 相关函数
函数包readr和readxl提供了一系列的数据读入功能,主要函数如下:
#readr包 read_delim(file, delim, quote = "\"", escape_backslash = FALSE, escape_double = TRUE, col_names = TRUE, col_types = NULL, locale = default_locale(), na = c("", "NA"), quoted_na = TRUE, comment = "", trim_ws = FALSE, skip = 0, n_max = Inf, guess_max = min(1000, n_max), progress = show_progress(), skip_empty_rows = TRUE) read_csv(file, col_names = TRUE, col_types = NULL, locale = default_locale(), na = c("", "NA"), quoted_na = TRUE, quote = "\"", comment = "", trim_ws = TRUE, skip = 0, n_max = Inf, guess_max = min(1000, n_max), progress = show_progress(), skip_empty_rows = TRUE) #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")
- 参数
- 举个例子
输入:
library(readr) library(readxl) cp <-read_delim("comp.csv", ",") cp.csv <- read_csv("comp.csv") cp.xl <- read_excel("comp.xlsx") #summary(cp.csv) #summary(cp.xl) system.time(read_csv("data.csv")) system.time(read.csv("data.csv"))
输出:
> system.time(read_csv("data.csv")) 用户 系统 流逝 0.88 0.00 0.89 Warning message: Duplicated column names deduplicated: 'DATE_R' => 'DATE_R_1' [48] > system.time(read.csv("data.csv")) 用户 系统 流逝 3.77 0.05 3.86
通过与R中的read.csv()函数进行比对,我们发现,利用函数包readr和readxl中的函数进行数据读入的速度有很大提升。
写入数据
函数包readr提供了数据读取功能的同时,还提供了数据写入功能,即将data.frame对象重新写为csv, xlsx,等格式的文件。
- 相关函数
write_delim(x, path, delim = " ", na = "NA", append = FALSE, col_names = !append, quote_escape = "double") write_csv(x, path, na = "NA", append = FALSE, col_names = !append, quote_escape = "double") write_excel_csv(x, path, na = "NA", append = FALSE, col_names = !append, delim = ",", quote_escape = "double")
- 参数
- 举个例子
输入:
df <- data.frame(x = c(1,2,3,4,5), y = c(6,7,NA,9,0)) write_delim(df, "df1.csv", delim = ",") write_csv(df, "df2.csv", na = "-")
df1.csv:
df2.csv:
-
学习笔记(二)tidyverse之readxl包------表格数据读取
2018-09-14 12:25:01readxl包是tidyverse中的一员,是导入Excel表格数据的一个R包,由Hadley Wickham开发的。与其他已经存在的包(例如:gdata包、xlsx包…)最大的区别是不依赖其他外部程序,能够在所有操作系统中都方便使用; 主要功能...1、readxl概况
readxl包是tidyverse中的一员,是导入Excel表格数据的一个R包,由Hadley Wickham开发的。与其他已经存在的包(例如:gdata包、xlsx包…)最大的区别是不依赖其他外部程序,能够在所有操作系统中都方便使用;
主要功能是导入xls/xlsx 文件;
官方链接: http://readxl.tidyverse.org/2、installation & library
方法一:从CRAN中安装在整个tidyverse包
#install.packages("tidyverse") library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.4.4
## -- Attaching packages ---------------------------------- tidyverse 1.2.1 --
## √ ggplot2 2.2.1 √ purrr 0.2.4
## √ tibble 1.4.2 √ dplyr 0.7.4
## √ tidyr 0.8.0 √ stringr 1.2.0
## √ readr 1.1.1 √ forcats 0.3.0## Warning: package 'ggplot2' was built under R version 3.4.1
## Warning: package 'tibble' was built under R version 3.4.4
## Warning: package 'tidyr' was built under R version 3.4.4
## Warning: package 'readr' was built under R version 3.4.4
## Warning: package 'purrr' was built under R version 3.4.4
## Warning: package 'dplyr' was built under R version 3.4.3
## Warning: package 'stringr' was built under R version 3.4.1
## Warning: package 'forcats' was built under R version 3.4.4
## -- Conflicts ------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()方法二:从Cran中直接安装readxl包
#install.packages("readxl") library(readxl)
## Warning: package 'readxl' was built under R version 3.4.4
3、Usage
readxl_example()
readxl包中含有一些例子,我们可以使用readxl_example()函数直接将它们展示出来,或者使用readxl_example("filename"")得到该文件的路径
readxl_example()
## [1] "clippy.xls" "clippy.xlsx" "datasets.xls" "datasets.xlsx"
## [5] "deaths.xls" "deaths.xlsx" "geometry.xls" "geometry.xlsx"
## [9] "type-me.xls" "type-me.xlsx"readxl_example("datasets.xls")
## [1] "D:/R-3.4.0/library/readxl/extdata/datasets.xls"
readxl_example("datasets.xlsx")
## [1] "D:/R-3.4.0/library/readxl/extdata/datasets.xlsx"
注:接下来使用datasets.xls及datasets.xlsx来分享readxl包中其他函数的使用方法
read_excel()
导入xls/xlsx函数
xls_eg <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls") xls_eg
## # A tibble: 150 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## # ... with 140 more rowsxlsx_eg <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xlsx") xlsx_eg
## # A tibble: 150 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## # ... with 140 more rows其他参数:
sheetsheet 导入某个特定的工作表,默认第一个工作表 range 导入表格中特定区域的数据, 默认全区域 col_names 列名,默认为TRUE(第一行为列名),设置为F, 则列名为X1、X2…,也可通过一个向量设置 特定列名 col_type 列的数据类型 n_max 设置读取最大的行数 na 默认表示数据中的缺失值,也可以将特定值设置为 缺失值 excel_sheets()
列出Excel文件中所有工作表名称
excel_sheets("D:/R-3.4.0/library/readxl/extdata/datasets.xls")
## [1] "iris" "mtcars" "chickwts" "quakes"
4、Case
excel_sheets("D:/R-3.4.0/library/readxl/extdata/datasets.xls")
## [1] "iris" "mtcars" "chickwts" "quakes"
xls_iris <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", sheet =1) xls_iris
## # A tibble: 150 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## # ... with 140 more rowsxls_iris1 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", range = "A1:E21") xls_iris1
## # A tibble: 20 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## 11 5.4 3.7 1.5 0.2 setosa
## 12 4.8 3.4 1.6 0.2 setosa
## 13 4.8 3 1.4 0.1 setosa
## 14 4.3 3 1.1 0.1 setosa
## 15 5.8 4 1.2 0.2 setosa
## 16 5.7 4.4 1.5 0.4 setosa
## 17 5.4 3.9 1.3 0.4 setosa
## 18 5.1 3.5 1.4 0.3 setosa
## 19 5.7 3.8 1.7 0.3 setosa
## 20 5.1 3.8 1.5 0.3 setosaxls_iris2 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", n_max = 20) xls_iris2
## # A tibble: 20 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## 11 5.4 3.7 1.5 0.2 setosa
## 12 4.8 3.4 1.6 0.2 setosa
## 13 4.8 3 1.4 0.1 setosa
## 14 4.3 3 1.1 0.1 setosa
## 15 5.8 4 1.2 0.2 setosa
## 16 5.7 4.4 1.5 0.4 setosa
## 17 5.4 3.9 1.3 0.4 setosa
## 18 5.1 3.5 1.4 0.3 setosa
## 19 5.7 3.8 1.7 0.3 setosa
## 20 5.1 3.8 1.5 0.3 setosaxls_iris3 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", range = cell_cols("B:D")) xls_iris3
## # A tibble: 150 x 3
## Sepal.Width Petal.Length Petal.Width
## <dbl> <dbl> <dbl>
## 1 3.5 1.4 0.2
## 2 3 1.4 0.2
## 3 3.2 1.3 0.2
## 4 3.1 1.5 0.2
## 5 3.6 1.4 0.2
## 6 3.9 1.7 0.4
## 7 3.4 1.4 0.3
## 8 3.4 1.5 0.2
## 9 2.9 1.4 0.2
## 10 3.1 1.5 0.1
## # ... with 140 more rowsxls_iris4 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", col_names = FALSE) xls_iris4
## # A tibble: 151 x 5
## X__1 X__2 X__3 X__4 X__5
## <chr> <chr> <chr> <chr> <chr>
## 1 Sepal.Length Sepal.Width Petal.Length Petal.W~ Spec~
## 2 5.0999999999999996 3.5 1.3999999999999999 0.20000~ seto~
## 3 4.9000000000000004 3 1.3999999999999999 0.20000~ seto~
## 4 4.7000000000000002 3.2000000000000002 1.3 0.20000~ seto~
## 5 4.5999999999999996 3.1000000000000001 1.5 0.20000~ seto~
## 6 5 3.6000000000000001 1.3999999999999999 0.20000~ seto~
## 7 5.4000000000000004 3.8999999999999999 1.7 0.40000~ seto~
## 8 4.5999999999999996 3.3999999999999999 1.3999999999999999 0.29999~ seto~
## 9 5 3.3999999999999999 1.5 0.20000~ seto~
## 10 4.4000000000000004 2.8999999999999999 1.3999999999999999 0.20000~ seto~
## # ... with 141 more rowsxls_iris5 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", col_names = c("x1","x2","x3","x4","y")) xls_iris5
## # A tibble: 151 x 5
## x1 x2 x3 x4 y
## <chr> <chr> <chr> <chr> <chr>
## 1 Sepal.Length Sepal.Width Petal.Length Petal.W~ Spec~
## 2 5.0999999999999996 3.5 1.3999999999999999 0.20000~ seto~
## 3 4.9000000000000004 3 1.3999999999999999 0.20000~ seto~
## 4 4.7000000000000002 3.2000000000000002 1.3 0.20000~ seto~
## 5 4.5999999999999996 3.1000000000000001 1.5 0.20000~ seto~
## 6 5 3.6000000000000001 1.3999999999999999 0.20000~ seto~
## 7 5.4000000000000004 3.8999999999999999 1.7 0.40000~ seto~
## 8 4.5999999999999996 3.3999999999999999 1.3999999999999999 0.29999~ seto~
## 9 5 3.3999999999999999 1.5 0.20000~ seto~
## 10 4.4000000000000004 2.8999999999999999 1.3999999999999999 0.20000~ seto~
## # ... with 141 more rowsxls_iris6 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", col_names = FALSE, col_types = "numeric") xls_iris6
## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in A1 / R1C1: got 'Sepal.Length'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in B1 / R1C2: got 'Sepal.Width'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in C1 / R1C3: got 'Petal.Length'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in D1 / R1C4: got 'Petal.Width'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in E1 / R1C5: got 'Species'## # A tibble: 151 x 5
## X__1 X__2 X__3 X__4 X__5
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 NA NA NA NA NA
## 2 5.1 3.5 1.4 0.2 NA
## 3 4.9 3 1.4 0.2 NA
## 4 4.7 3.2 1.3 0.2 NA
## 5 4.6 3.1 1.5 0.2 NA
## 6 5 3.6 1.4 0.2 NA
## 7 5.4 3.9 1.7 0.4 NA
## 8 4.6 3.4 1.4 0.3 NA
## 9 5 3.4 1.5 0.2 NA
## 10 4.4 2.9 1.4 0.2 NA
## # ... with 141 more rowsxls_iris7 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", col_names = c("x1","x2","x3","x4","y"), col_types = c("numeric","numeric","numeric","numeric","text")) xls_iris7
## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in A1 / R1C1: got 'Sepal.Length'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in B1 / R1C2: got 'Sepal.Width'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in C1 / R1C3: got 'Petal.Length'## Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
## shim, : Expecting numeric in D1 / R1C4: got 'Petal.Width'## # A tibble: 151 x 5
## x1 x2 x3 x4 y
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 NA NA NA NA Species
## 2 5.1 3.5 1.4 0.2 setosa
## 3 4.9 3 1.4 0.2 setosa
## 4 4.7 3.2 1.3 0.2 setosa
## 5 4.6 3.1 1.5 0.2 setosa
## 6 5 3.6 1.4 0.2 setosa
## 7 5.4 3.9 1.7 0.4 setosa
## 8 4.6 3.4 1.4 0.3 setosa
## 9 5 3.4 1.5 0.2 setosa
## 10 4.4 2.9 1.4 0.2 setosa
## # ... with 141 more rowsxls_iris8 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls",na = "setosa") xls_iris8
## # A tibble: 150 x 5
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## <dbl> <dbl> <dbl> <dbl> <chr>
## 1 5.1 3.5 1.4 0.2 <NA>
## 2 4.9 3 1.4 0.2 <NA>
## 3 4.7 3.2 1.3 0.2 <NA>
## 4 4.6 3.1 1.5 0.2 <NA>
## 5 5 3.6 1.4 0.2 <NA>
## 6 5.4 3.9 1.7 0.4 <NA>
## 7 4.6 3.4 1.4 0.3 <NA>
## 8 5 3.4 1.5 0.2 <NA>
## 9 4.4 2.9 1.4 0.2 <NA>
## 10 4.9 3.1 1.5 0.1 <NA>
## # ... with 140 more rowsxls_mtcars <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", sheet = 2) xls_mtcars
## # A tibble: 32 x 11
## mpg cyl disp hp drat wt qsec vs am gear carb
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
## 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
## 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
## 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
## 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
## 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
## 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
## 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
## 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
## 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
## # ... with 22 more rowsxls_mtcars1 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", sheet = "mtcars") xls_mtcars1
## # A tibble: 32 x 11
## mpg cyl disp hp drat wt qsec vs am gear carb
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
## 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
## 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
## 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
## 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
## 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
## 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
## 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
## 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
## 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4
## # ... with 22 more rowsxls_mtcars2 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", range = "mtcars!a1:f10") xls_mtcars2
## # A tibble: 9 x 6
## mpg cyl disp hp drat wt
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 21 6 160 110 3.9 2.62
## 2 21 6 160 110 3.9 2.88
## 3 22.8 4 108 93 3.85 2.32
## 4 21.4 6 258 110 3.08 3.22
## 5 18.7 8 360 175 3.15 3.44
## 6 18.1 6 225 105 2.76 3.46
## 7 14.3 8 360 245 3.21 3.57
## 8 24.4 4 147. 62 3.69 3.19
## 9 22.8 4 141. 95 3.92 3.15xls_mtcars3 <- read_excel("D:/R-3.4.0/library/readxl/extdata/datasets.xls", sheet =2, range = cell_rows(1:11)) xls_mtcars3
## # A tibble: 10 x 11
## mpg cyl disp hp drat wt qsec vs am gear carb
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
## 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
## 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
## 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1
## 5 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2
## 6 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1
## 7 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4
## 8 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
## 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
## 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 -
tidyverse —— readxl包
2018-06-20 11:34:48readxl包,读取Excel文件专用包,有和tidyverse核心包一样的特点,快!效率特高! 话说Hadley大叔出品就没有效率低的,可能键盘是借来的,着急还。 独立性高,不外部依赖Java啥的,xls和xlsx文件读取都可以。 ... -
R语言循环过程和readxl包的使用
2021-02-22 15:24:53之前R语言xlsx包的一些问题: 1)安装问题;...library(readxl) (1)xlsx包的作者很久没有更新了,最后更新日期在2014-08-22,所依赖的poi版本是3.1(Java11),而目前电脑的版本(java15),现在的p. -
规模数据导入高效方式︱将数据快速读入R—readr和readxl包
2017-01-06 10:17:41本文由雪晴数据网负责翻译整理,原文请参考New packages for reading data into R —... 昨天在新电脑使用xlsx包的时候,因为加载rJava十分不悦…于是用了readxl,不要太方便,于是转一篇过来备用着。以后读入都用你了~ -
EXCEL 导入 R 的几种方法 R—readr和readxl包
2019-10-04 07:24:54将数据快速读入R—readr和readxl包 大 数 据 人 报道DT时代应用资讯及动态,爆料剖析行业热点新闻 Hadley Wickham 和 RStudio团队写了一些新的R包,这些包对于每个需要在R中读入数据的人来说都是非常... -
读取excel显示错误_R包readxl 的libxls读错误的解决方法
2021-01-03 03:54:45R包readxl 的libxls读取错误解决方法缘起:xls转化为...结果xls文件不能被readxl包打开。read_xls('bad.xls')Error: filepath: bad.xls libxls error: Unable to open file千辛万苦安装了各种读取xls的R包,一一失败... -
R语言---安装依赖包
2020-12-16 15:32:15在此以readxl包为例: 安装方法一: 1、打开R x64 4.0.3,使用 install.packages("readxl"); 默认安装目录时,如果电脑的名称为中文,在运行例如Rserve服务时,会出现找不到路径的情况,或者提示“多字节字符串有... -
Rstudio xlsx包读取xlsx报错 Error in .jcall(cell, “D“, “getNumericCellValue“) : java.lang....
2020-07-02 18:55:45Rstudio xlsx包读取xlsx报错 Error in .jcall(cell, “D”, “getNumericCellValue”) : java.lang.OutOfMemoryError: GC overhead limit exceeded 换readxl包即可。 -
R 读取excel的方法
2019-09-22 16:07:311.加载 readxl 包,利用 reade_excel() 函数 install.packages("readxl") library(readxl) data = read_excel("22_data.xlsx",sheet = 1) read_excel函数的参数设置: 用法:read.xlsx(xlsxFile, sheet = 1... -
R中openxlsx读取excel2003版xls报错: openxlsx can not read .xls or .xlm files!
2020-05-27 07:38:12报错信息: openxlsx can not read .xls or .xlm files! 报错原因: openxlsx不支持2003版excel格式的...解决方法:使用readxl包 library(readxl) tt= read_xls("test.xls") head(tt);dim(tt) 用法和openxlsx一致。 -
R导入excel数据
2020-12-20 17:28:03readxl包 临床中很多数据是使用excel保存的,但是R语言目前并不支持直接读入excel数据,加载合适的包可以解决这个问题。 library(readxl) read_excel("path/file",sheet="") #在逗号前选择文件路径及文件名,sheet中... -
R ggplot2线性图
2017-08-06 15:04:52#若没有下载过readxl包,则有此步,否则直接跳过 install.packages(“readxl”)#使用包 library(readxl)#读取excel文件 dataset(path=“./records_data.xlsx”,sheet=”Fe”,range=”A2:G18”) #解析 path参数表明... -
ggbiplot设置分组_R IN ACTION SELF-TUTORIAL-53 ggbiplot做PCA分析 2020-12-24
2021-01-13 22:15:55pca-1circle.png清理历史记录rm(list = ls())数据准备与读取数据表事先安装读取xl文件的readxl包:install.packages("readxl")原始数据如下(存于xls文件中):Ca N P Fe Mg GrowthPLANT1 1 21 3 3 12 32PLANT2 2 32 ... -
R读取xlsx文件
2018-02-09 10:28:55目前发现R中最方便的excel文件读取方法为readxl包,首先按照R包: install.packages(‘readxl’, repos = ‘https://mirrors.tuna.tsinghua.edu.cn/CRAN‘) install.packages(‘rlang’, repos = ... -
R导入数据
2019-01-08 11:04:18readxl包 #下载和引用 install.packages("readxl") library(readxl) #读取Excel read_excel("old_excel.xls") read_excel("new_excel.xlsx") ... -
2.3.3 导入Excel数据(read_excel())
2019-05-19 21:32:402.3.3 导入Excel数据(read_excel()) 读取一个Excel文件的最好方式,就是在Excel中将其导出为一个逗号分隔文件(csv),并使用...你也需要readxl包,install.packages(“readxl”)安装包命令。 xlsx包可以用来对Excel 9... -
r数据处理与echart作图总结
2019-09-18 21:25:591)readxl包 library(readxl) path<-"D:\\xiangmu\\lixueyuan\\data1.xls" data<-read_excel(path,range="A1:BU221") 2)对某一列数据分类计数并位dataframe格式 as.data.frame(table(data$性别)) ##进行计数 ... -
R语言小代码6(股票数据分析)
2020-04-04 15:41:25任务:一:请举例说明R...下载readxl包,使用read_xlsx方法,注明路径和sheet名字,就能读取不同工作表的内容 代码: > library("readxl") > getwd() [1] "C:/Users/lenovo/Documents" > > read_sheet... -
R读写外部文件
2018-09-03 19:38:15目录 read.table()方法 read.csv()方法 readxl包 内容 read.table()方法 bank1 <- read.table('user_info.txt', header = F, sep = ',', ... -
R语言读取不规则表格
2020-08-19 10:39:57使用 readxl 包,感觉比别的包方便多了。 功能快捷键 撤销:Ctrl/Command + Z 重做:Ctrl/Command + Y 加粗:Ctrl/Command + B 斜体:Ctrl/Command + I 标题:Ctrl/Command + Shift + H 无序列表:Ctrl/Command + ...
-
Galera 高可用 MySQL 集群(PXC v5.7+Hapro)
-
POJ-1556题解(附带计算几何模板)
-
猫眼dubbo笔记.docx
-
朱老师c++课程第3部分-3.5STL的其他容器讲解
-
MySQL NDB Cluster 负载均衡和高可用集群
-
MOG_BattleCursor.js
-
Docker从入门到精通
-
Scrum敏捷项目管理要点总结.pdf
-
uploadifive上传图片源码附教程文档.zip
-
什么是Armbian
-
模块2Python语言基础.pptx
-
蓝桥杯学习记录6
-
执行yum时,报错error: rpmdb: BDB0113 Thread/process 13132/139729145776192 failed: BDB1507 Thread died in B
-
自动化测试Python3+Selenium3+Unittest
-
堡垒机安装配置
-
使用神经网络的自动化特征工程
-
弹窗提示 运行之后 右键单击可退出
-
Windows系统管理
-
MySQL你该了解的那些事【服务端篇】
-
虚幻4引擎基础