[R] Help with locating error on import of data

Rasmus Liland jr@| @end|ng |rom po@teo@no
Tue Jun 23 23:19:27 CEST 2020


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200623/654d1daa/attachment.sig>


More information about the R-help mailing list