Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Import two dataframes from the same excel sheet in Rstudio as separated dataframes

I have an excel file named "inner_merge" which in first sheet named "original" contains 2 separated dataframes exactly like in the image below. The first one has columns id,type,state,zip and the second id1,type1,city1,state1,zip1,data,data_1,data_2 I would like to know how could I import those two in Rstudio as separated dataframes, avoiding to create two separated excel files.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With readr::read_excel you can use the range argument to specify which cells to read in. So you can use it once specifying columns A-E and again specifying columns H-P. See ?read_excel and ?cell-specification for details.

From your picture, you want something like this:

library(readxl)
library(cellranger)

df1 = read_excel(path, range = cell_cols("A:E"))
df2 = read_excel(path, range = cell_cols("H:P"))

Where path is the path to your excel file. You may also need to specify which sheet to read from if there are more than one.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading