r - Reading specific columns and rows from excel sheet in R
问题描述
I have a large xlsx file called Run.xlsx. Inside this are multiple sheets and I want the sheet called "Factors". I also want to extract specific rows and columns from the factors sheet which are columns Z:AB and rows 15:71.
I have tried using the readxl package however it doesn't work for me.
解决方案
If your Excel file columns order may change, it would be best to have an automatic code instead of selecting the columns number.
You could try
1- importing your xlsx file with "read.xlsx" function from "openxlsx" library
2- selecting columns with specific name
#1-import
library(openxlsx)
yourFile <- read.xlsx("yourPathway/yourFile.xlsx", sheet="yourSheet")
#2-columns selection
vectorNameColumns <- c("Age", "BMI", ..., "Gender")
vectorNameRows <- 15:71
refinedFile <- yourFile[vectorNameRows, vectorNameColumns]
It would also be best (for safety and time consuming purpose) to automatically select specific row names or IDs instead of row numbers in the case where your Excel file would be modified or if you want to apply the same code to another Excel file.
推荐阅读
- android - 在 webview 和 Chrome 浏览器上打开链接
- c# - 使用存储过程的问题以及下一步做什么
- php - PHP Null 合并运算符混淆
- python-3.x - 在大型数据集中找到 10 个最小的数字?
- java - ASCII 错误消息,找不到符号
- google-chrome - 在 about:tracing through Selenium 点击 Record 按钮
- python - Django 的 reverse() 函数是否将列表作为参数?
- android - Android Studio 不会突然构建:程序类型已经存在:com.google.android.gms.internal.auth.zzao
- android - 如何安装 Firebase Crashlytics
- sentry - 如何修复 Raven/Sentry 的 mocha Javascript 测试?