数据帧是可见的,没有任何错误.但当使用write打印时.xlsx功能的xlsx包,它给出了错误.

Error in .jcall(cell, "V", "setCellValue", value) : 
  method setCellValue with signature ([D)V not found.

数据的dput.框架看起来像:

Timestamp         qs          pqs        logqs         es         p_imp      dep    r_dep       agg_rtn
               (time)      (dbl)        (dbl)        (dbl)      (dbl)         (dbl)    (dbl)    (dbl)         (dbl)
1 2015-05-04 09:29:59 0.05788732 0.0007478696 0.0007478545 0.09633803 -0.0446830986 3533.518 274079.9 -0.0006432937
2 2015-05-04 10:00:00 0.04948394 0.0006362707 0.0006362707 0.07586009  0.0088016055 2416.431 187953.1  0.0000000000
3 2015-05-04 10:30:00 0.05554795 0.0007142532 0.0007142532 0.06417808 -0.0002739726 3245.574 252422.0  0.0000000000
4 2015-05-04 10:59:59 0.04863014 0.0006194244 0.0006194244 0.08434442  0.0024951076 3563.401 279503.9  0.0000000000
5 2015-05-04 11:30:00 0.05761986 0.0007319037 0.0007319037 0.07851027  0.0154965753 2010.943 158429.1 -0.0006339144
6 2015-05-04 12:00:00 0.04957627 0.0006285051 0.0006285051 0.07025424  0.0070762712 1819.908 143546.0  0.0000000000
Variables not shown: vol_30_sum (dbl), vol_30_mean (dbl), p_return_sqr (dbl), p_return_mean (dbl), Lim_or_out (dbl),
  closing_price (dbl), closing_vol (dbl)

请帮忙解决这个错误.

推荐答案

仍然没有可复制的示例,但从您的class(q1)来看,q1似乎是tbl_df(dplyr包生成的数据帧类型),而write.xlsx预期是data.frame.

试着给write.xlsx一个普通的data.frame.例如

write.xlsx(as.data.frame(q1), ...)

这里有一个100(也就是说,你可以将它复制粘贴到你的R会话中,以重现bug+fix).

library(dplyr)
iris2 <- tbl_df(iris)
class(iris2) # like yours
# [1] "tbl_df"     "tbl"        "data.frame" 

# Now let's try to write to XLSX using command as mentioned in your comments
library(xlsx)
write.xlsx(iris2, file='test.xlsx', sheetName="Sheet1", col.names=TRUE, row.names=FALSE, append=TRUE)
# Error in .jcall(cell, "V", "setCellValue", value) : 
#   method setCellValue with signature ([D)V not found
# In addition: Warning message:
# In if (is.na(value)) { :
#  the condition has length > 1 and only the first element will be used
# ^--- we can reproduce your error. This is the point of a reproducible example, so we can see if our fixes work for you.

现在,让我们试着通过确保.xlsx获取数据.框架,不是tbl_df!

write.xlsx(as.data.frame(iris2), file='test.xlsx', sheetName="Sheet1", col.names=TRUE, row.names=FALSE, append=TRUE)
# huzzah!

R相关问答推荐

R中的Fasttext langue_identification返回太多参数-如何与文本匹配?

在R中使用自定义函数时如何删除该函数的一部分?

给定R中另一行中的值,如何插补缺失值

在通过最大似然估计将ODE模型与数据匹配时,为什么要匹配实际参数的转换值?

在ggplot Likert条中添加水平线

更新合适的R mgcv::bam模型报告无效类型(关闭).'';错误

更改Heatmap Annotation对象的名称

如何在R中合并两个基准点?

Ggplot2中的重复注记

在不丢失空值的情况下取消列出嵌套列表

如何从容器函数中提取conf并添加到ggplot2中?

将箭头绘制在图形外部,而不是图形内部

R如何将列名转换为更好的年和月格式

提高圣彼得堡模拟的速度

将摘要图添加到facet_WRAP gglot的末尾

将多个列合并为一个列的有效方法是什么?

将列表中的字符串粘贴到R中for循环内的dplyr筛选器中

将数据从一列转换为按组累计计数的单个虚拟变量

有没有办法更改ggplot2中第二个y轴的比例限制?

如何在不使用SHINY的情况下将下拉滤镜列表添加到ggploy?