无法从csv文件导出相同格式的数据

时间:2019-04-16 09:41:11

标签: r

我有一个.csv文件,其中包含50列,包括文本,数字,数量和百分比。当我将数据导出到.xlsx中时,所有金额和百分比列都将转换为文本。有帮助吗?

我的下面的代码:

datafile <- choose.files("", caption = " Select files ")
data <- read.csv(datafile, header = TRUE, sep = "," )

write.xlsx(data, file = "abc.xlsx" , sheetName = "UtilizationReportGRE", row.names = F)

1 个答案:

答案 0 :(得分:1)

Write.xlsx将因子转换为字符串。在使用write.xlsx之前,请更改数据以使数字列变为数字等。另请参见How to convert a data frame column to numeric type?