Skip to content
Back to formatted view

Raw Message

Message-ID: <21746719-e669-6e39-6435-e263f63ec7e8@sapo.pt>
Date: 2022-08-24T05:40:00Z
From: Rui Barradas
Subject: Read excel specific column
In-Reply-To: <CAG0CrLiFZQsM17SRga2wT9s+NF3pUFw8Pdwb-BDjbRKjAoSEyA@mail.gmail.com>

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:
> I have .xlsx files with gene names in first column.How can read and load in
> R?
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.