Extract data from an Excel table

I am interested in the option of writing code for the next task.

I have 4 Excel documents with one random number on the first sheet in each of them (in a random place). I need to extract these numbers with R.

Could you help me, please?

1 Like

I have found the package openxlsx to be useful for reading Excel files. The read.xlsx() function, documented at https://www.rdocumentation.org/packages/openxlsx/versions/4.1.0/topics/read.xlsx, may well do what you need. Without much more detail about how to identify the number you want to extract, it is difficult to be more specific.

Excel sheets are potentially very huge. Do you have any idea of how many rows or columns you need to search? You can use read_xlsx() from the readxl package, similar to what FJCC suggested.

df <- read_xlsx(file_name, range="A1:Z1000") # read excel sheet into dataframe
value <- df[!is.na(unlist(df))] # unlist to convert df to vector, then find non-missing value

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.