我有一张 Excel 表格.xlsx,其中有一些注释的单元格。导入R后,R有什么办法可以识别注释的单元格吗?
因为我必须仅对注释的单元格使用一些 if else 条件。
Let's say we have this file, test.xlsx
:
![enter image description here](https://i.stack.imgur.com/CrRSN.png)
Using openxlsx我们可以将工作簿作为数据框对象读取以仅提取数据:
library(openxlsx)
# read the data
df1 <- read.xlsx("test.xlsx")
df1
# 1 no
# 1 2 yes
# 2 3 no
# 3 5 no
# 4 10 yes
如果我们需要提取注释,我们需要读取工作簿对象:
# read as workbook object
wb <- loadWorkbook("test.xlsx")
检查对象的结构以查看单元格引用的存储位置:
str(wb$comments)
# List of 3
# $ :List of 2
# ..$ :List of 5
# .. ..$ ref : chr "B2"
# ...
# ... etc
然后子集、循环工作表以及子集单元格引用和注释:
lapply(wb$comments, function(sheet)
sapply(sheet, "[[", "ref"))
# [[1]]
# [1] "B2" "B5"
#
# [[2]]
# list()
#
# [[3]]
# list()
这意味着有 3 张纸,第 1 张纸在 B2 和 B5 处有 2 个注释,其他 2 张纸是空白的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)