[R] readxl question

Thomas Subia t@ub|@ @end|ng |rom |mgprec|@|on@com
Thu Dec 5 16:39:56 CET 2019


Colleagues,

I'm trying to extract a cell from all Excel files in a directory.

library(readxl)
files <- list.files(pattern="*.xls", full.names = FALSE)

date <- lapply(files, read_excel, sheet="Sheet1", range=("B5"))

date_df <- as.data.frame(date)
trans_date <-t(date_df)
mydates <- list(trans_date)
write.table(mydates,"mydates.txt",sep="\t")

Looking at mydates.txt shows:

""
"Saturday..June.09..2018"	
"Saturday..June.09..2018.1"	
"Saturday..June.09..2018.2"

But the original Excel contents are:

Saturday, June 09, 2018
Saturday, June 09, 2018
Saturday, June 09, 2018

I get a similar problem with my serial numbers

serial <-lapply(files, read_excel, sheet="Sheet1", range=("B9"))

serial_df <- as.data.frame(serial)
trans_serial <-t(serial_df)
myserials <- list(trans_serial)
write.table(myserials,"myserials.txt",sep="\t")

R Output

""
"X96739.0027.1"	
"X96739.0041.1"	
"X96739.0044.1"	

Original Excel Content
96739-0027/1
96739-0041/1
96739-0044/1

How can I amend my script so that the output matches the original Excel content?

Thomas Subia 
Statistician / Senior Quality Engineer
IMG Precision



More information about the R-help mailing list