Created
September 23, 2017 17:23
-
-
Save aravindhebbali/65dc2af57b8eda098f2b878095c5aaa4 to your computer and use it in GitHub Desktop.
A Complete Guide to Importing Data into R - Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install | |
install.packages('readxl') | |
# library | |
library(readl) | |
# list sheets | |
excel_sheets('sample2.xls') | |
# read data from sheet 1 | |
read_excel('sample2.xls', sheet = 1) | |
# read data from sheet 2 | |
read_excel('sample2.xls', sheet = 2) | |
# read data from cells B3 to C7 | |
# read data from rows 3 to 7 of columns 2 & 3 | |
read_excel('sample2.xls', sheet = 2, range = "B3:C8") | |
# generate column names | |
read_excel('sample2.xls', sheet = 2, range = "B3:C8", col_names = FALSE) | |
# specify column names | |
read_excel('sample2.xls', sheet = 2, range = "B3:C8", col_names = c("Strain", "Res_4")) | |
# read data from 3 rows and 2 columns starting at the cell `A4` | |
read_excel('sample2.xls', sheet = 2, col_names = FALSE, | |
range = anchored("A4", dim = c(3, 2))) | |
# read all the cell from the third row of the 1st column to the 5th row of the second column | |
read_excel('sample2.xls', sheet = 2, range = cell_limits(c(3, 1), c(5, 2))) | |
# read second column | |
read_excel('sample2.xls', sheet = 2, range = cell_cols(2)) | |
# read second row | |
read_excel('sample2.xls', sheet = 2, range = cell_rows(2)) | |
# column type | |
read_excel('sample2.xls', sheet = 2, col_types = c("numeric", "text", "numeric")) | |
# skip first 3 rows | |
read_excel('sample2.xls', sheet = 2, skip = 3, col_names = FALSE) | |
# read 10 rows | |
read_excel('sample2.xls', sheet = 2, n_max = 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment