Skip to content
Prev 392475 / 398502 Next

Read excel specific column

Hello,

The examples below use packages readxl and cellranger.


# to read the 1st column of a xlsx file named filename:
library(readxl)

read_xlsx(filename, range = cellranger::cell_cols("A"))

# to read 1st column of all files in filenames_vec
# result is a list of data.frames each of them with
# one column only
gene_names_list <- lapply(filenames_vec, \(x) {
   read_xlsx(x, range = cellranger::cell_cols("A"))
})

# to read 1st column of all files in filenames_vec
# result is a vector
gene_names_vec <- lapply(filenames_vec, \(x) {
   read_xlsx(x, range = cellranger::cell_cols("A"))[[1]]
})
gene_names_vec <- unlist(gene_names_vec)



If the files are xls, not xlsx, use read_xls; if you don't know, 
read_excel will call the right function.


Hope this helps,

Rui Barradas


?s 00:49 de 24/08/2022, Anas Jamshed escreveu: