[R] read.xls without row number, column numbers, or factors

David Carlson dc@r|@on @end|ng |rom t@mu@edu
Tue Jul 2 17:18:41 CEST 2019


Converting a one-row data frame to a list is not difficult, but there
are several ways to represent the data as a list. Here is a
possibility:

> dta <- data.frame(t(LETTERS[1:10]), stringsAsFactors=FALSE)
> dta
  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1  A  B  C  D  E  F  G  H  I   J
> dta.lst <- as.list(unname(dta))
> str(dta.lst)
List of 10
 $ : chr "A"
 $ : chr "B"
 $ : chr "C"
 $ : chr "D"
 $ : chr "E"
 $ : chr "F"
 $ : chr "G"
 $ : chr "H"
 $ : chr "I"
 $ : chr "J"

--------------------------------
David L Carlson
Anthropology Department
Texas A&M University

On Tue, Jul 2, 2019 at 9:34 AM Ivan Krylov <krylov.r00t using gmail.com> wrote:
>
> On Mon, 01 Jul 2019 20:13:34 -0400
> asteya using mathnmaps.com wrote:
>
> > Is there a way to use read.xls to copy a portion of a single row of
> > an XLS spreadsheet to a list, without getting assigning row and
> > column numbers, and, if the data consists of strings, without
> > assigning levels?
>
> If you mean the read.xls function from gdata package, it uses read.csv
> to read the temporary CSV file produced from the XLS file and passes its
> arguments using ..., so it should be possible to pass as.is = TRUE and
> prevent factors from appearing.
>
> It doesn't seem to be possible to prevent row and column names from
> being produced (except passing header = F if your CSV doesn't have a
> header).
>
> The readxl[*] package offers somewhat saner defaults, so you might want
> to try that, too.
>
> --
> Best regards,
> Ivan
>
> [*] https://urldefense.proofpoint.com/v2/url?u=https-3A__readxl.tidyverse.org_&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=s6RiIjcvAhy9p3vCQ3IDY_pMKDIbJiJ19N3qoaMBdbo&s=wksjPQ0xfh5OAk0mgysq2vQ14kBIKPHysHxS9HLBvhQ&e=
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=s6RiIjcvAhy9p3vCQ3IDY_pMKDIbJiJ19N3qoaMBdbo&s=lnFWD1ZhtIQG1olqJnp7SIngLVTRqXOJujo2Flejesw&e=
> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=u6LDEWzohnDQ01ySGnxMzg&r=VAaHUElasUXjP9TzIcfIrXdkDpHnJBBZ9Q1u5LcXz9s&m=s6RiIjcvAhy9p3vCQ3IDY_pMKDIbJiJ19N3qoaMBdbo&s=FMnhiFANOvftI6jg5OxVSP4w3bKgFR1t9X5JMmgQrqc&e=
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list