R 中的 write.xlsx 在单元格中给出不正确的 NA [英] write.xlsx in R giving incorrect NA in cell

查看:37
本文介绍了R 中的 write.xlsx 在单元格中给出不正确的 NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些 NA 值的 zoo 对象,我正在使用 xlsx 包中的 write.xlsx 命令将其写入 Excel 文件.但是,它没有在需要的地方在 Excel 文件中提供 NA,而是提供了 Excel 无法使用的 #N/A.这是正常行为吗?如果是这样,是否还有其他办法?

I have a zoo object which contains some NA values within it and I am writing it to an Excel file using the write.xlsx command from the xlsx package. However instead of giving NA in the Excel file where required it provides #N/A which Excel has trouble working with. Is this normal behaviour? If so, is there anyway around this?

这是一个例子

y <- zoo(c(1:40), as.Date(1:40))
y[20] <- NA
write.xlsx(y, file = "test.xlsx")

非常感谢

推荐答案

这可以通过使用 R 或 Excel 来完成

This can be done either by using R or Excel

使用 xlsx 包,您可以将 NA 值保留为空白单元格

Using the xlsx package, you can leave NA values as blank cells

 write.xlsx(y, file = "test.xlsx", showNA=FALSE)

使用 excel 您可以忽略 NA 值.记得按 ctrl +shift+enter

Using excel you can ignore the NA values. Remember to press ctrl +shift+enter

{=SUM(IF(ISNA(A3:D3),0,A3:D3))}

这篇关于R 中的 write.xlsx 在单元格中给出不正确的 NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆