r語言對excel數據的分析「r語言讀取excel數據」

R語言中有很多讀取Excel文件的Package,如RODBC、xlsx、gdata、xlsReadWrite等,但都有很多缺點(依賴Java,依賴操作系統,列數限制、效率等等),而下面要介紹的兩個包可以完美地解決這些問題。

知識點

  • openxlsx: simplifies the the process of writing and styling Excel xlsx files from R and removes the dependency on Java.
  • readxl: Read Excel Files. Works on Windows, Mac and Linux without external dependencies.

包安裝

install.packages("openxlsx")
install.packages("readxl")

Read Excel file

# readxl 自帶的excel文件
xls_file <- readxl::readxl_example("datasets.xls")
xlsx_file <- readxl::readxl_example("datasets.xlsx")

readxl::read_xls(xls_file)
readxl::read_xlsx(xlsx_file)
openxlsx::read.xlsx(xlsx_file)

Write Excel file

xlsx_file <- readxl::readxl_example("datasets.xlsx")
df <- openxlsx::read.xlsx(xlsx_file)
openxlsx::write.xlsx(df, file = "datasets.xlsx")

Edit Excel file

openxlsx 具有以下功能:

  • 操作 WorkSheet
  • 操作 Cell & Style
  • 插入圖片
  • 函數
  • 設置行高、列寬
  • 格式化等等

Reference

  • https://ycphs.github.io/openxlsx/index.html
  • https://readxl.tidyverse.org/

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/202150.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-06 14:08
下一篇 2024-12-06 14:08

相關推薦

發表回復

登錄後才能評論