[R] read.xlsx - write.xlsx: reading/writing numbers as character

Mohsen Jafarikia jafarikia at gmail.com
Thu Jan 14 17:20:17 CET 2016


Hello:

I am reading some excel files (each with one sheet) and trying to write
them all in one file. I am not sure if read.xlsx reads some of the columns
as character or write.xlsx writes them as character where they are not
characters. I have 12 columns (2 character and 10 numbers). From 10 number
columns, with float and integer numbers, only 3 of them are recognized
correctly. I was wondering how can I define the the column format for
read.xlsx - write.xlsx.

Here comes a simple example of my code:

ifn1 <- "A.xlsx"
dat1  <- read.xlsx(ifn1, sheetName="A.csv", header = TRUE)

ifn2 <- "F.xlsx"
dat2  <- read.xlsx(ifn2, sheetName="F.csv",header = TRUE)

write.xlsx(dat1,  file="AF.xlsx", sheetName="A",   showNA=FALSE,
row.names=FALSE, append=FALSE)
write.xlsx(dat2,  file="AF.xlsx", sheetName="F",   showNA=FALSE,
row.names=FALSE, append= TRUE)

Thanks in advance!
Mohsen

	[[alternative HTML version deleted]]



More information about the R-help mailing list