English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Excel files in the format of xls or xlsx can be directly read in R language by importing the xlsx library.
R 语言读写 Excel 文件需要安装扩展包,我们可以在 R 到控制台输入以下命令来安装:
R language reading and writing Excel files require the installation of extension packages, and we can input the following command into the R console to install:}//install.packages("xlsx", repos = "https:/mirrors.ustc.edu.cn/CRAN
)
The installation process is as follows:
In fact, almost all Excel software and most table software support CSV format data, so it is completely possible to interact with R through CSV without using Excel.
# Check if xlsx is installed successfully: # Verify if the package is installed # Load package library("xlsx") library("xlsx")
The output result of executing the above code is:
[1] TRUE Loading required package: rJava Loading required package: methods Loading required package: xlsxjars
Excel File Data:
id Name url Likes 1 Google www.google.com 111 2 w3codebox www.oldtoolbag.com 222 3 Taobao www.taobao.com 333
You can copy and paste the above data into excel for testing.
Next, we can use the read.xlsx() function to read Excel data:
# Read the first sheet data of sites.xlsx data <- read.xlsx("sites.xlsx", sheetIndex = 1) print(data)