On 2020-06-23 17:24 +0100, Rui Barradas wrote:
> Às 15:56 de 23/06/2020, Ahson via R-help escreveu:
> > I have imported data from an Excel file 
> > and I am getting errors:
> 
> Try setting argument col.names = FALSE, it 
> seems that the function is not find column 
> headers and is choosing its own.

Dear Ahson,

The openxlsx package is also worth checking 
out for situations like this one.

First read the file into a workbook object, 
then read the sheet names from the workbook, 
lastly use the sheet names to read each sheet 
from the workbook using lapply:

        xlsxFile <- "hmm.xlsx"
        wb <- openxlsx::loadWorkbook(xlsxFile)
        sheets <- names(wb)
        list.of.sheet.dfs <- lapply(sheets, function(sheet, wb) {
          openxlsx::read.xlsx(
            xlsxFile=wb,
            sheet=sheet,
            colNames=FALSE)
        }, wb=wb)
        names(list.of.sheet.dfs) <- sheets
        list.of.sheet.dfs

yields:

        $Sheet1
             X1   X2   X3        X4     X5
        1  this <NA> <NA> blablabla   <NA>
        2  <NA> does <NA>      <NA>   <NA>
        3  <NA> <NA> <NA>       not   <NA>
        4  <NA> <NA> make      <NA>   <NA>
        5 sense <NA> <NA>      <NA>     42
        6  <NA> <NA> <NA>      <NA> lalala
        
        $ReallyComplexSamples0003
            X1      X2   X3    X4     X5     X6   X7
        1 <NA>    <NA> <NA>  <NA>   <NA>   <NA> some
        2 <NA>    <NA> with  <NA>   <NA> other  <NA>
        3 <NA> random  <NA>  <NA>   <NA>   <NA> <NA>
        4 info    <NA> <NA> sheet   <NA>   <NA> <NA>
        5 <NA>  stuck    in  <NA>   <NA>   <NA> <NA>
        6 <NA>    <NA>   it  <NA> lalala    $$$ <NA>
        7 <NA>    <NA> <NA>  <NA>   <NA>      2 <NA>

Best,
Rasmus

Attachment: signature.asc
Description: PGP signature

______________________________________________
R-help@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.

Reply via email to