Data import and text to column (when in excel A1 = 1+1+1 and 3 is visible)

ぐ巨炮叔叔 提交于 2019-12-11 05:49:40

问题


Let's say we have the excel file and in A1 we have formula = 1+1+1. So excel shows 3 however you can do 'Text to Columns' and value 1 will be in A1, B1 & C1.

Is there anything we can do in R after data import (I use read.xlsx) to get the same result (1,1,1 as oppose to just 3)?

Just to confirm, the original df is 1x1 with value 3 and the desired outcome is df 1x3 with 1 in all 3 cells.


回答1:


Not the full answer, but should get you started. If we have this example file:

We can use openxlsx package to get the formula:

library(openxlsx)

# read as workbook object
wb <- loadWorkbook("test.xlsx")

# get the 1st sheet
sheet1 <- wb$worksheets[[1]]

# get the cell formulas
sheet1$sheet_data$f
# [1] NA             "<f>1+1+1</f>" NA

Here, we can see the formula, the second item in sheet1$sheet_data$f. Meaning 1st column 2nd row. The rest of the job is to parse it into data.frame columns.



来源:https://stackoverflow.com/questions/49628570/data-import-and-text-to-column-when-in-excel-a1-111-and-3-is-visible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!