R对使用';函数创建的对象使用write.xlsx时出错;dplyr';

R对使用';函数创建的对象使用write.xlsx时出错;dplyr';,r,dataframe,dplyr,xlsx,R,Dataframe,Dplyr,Xlsx,当我试图使用xlsx软件包中的函数write.xlsx将数据框写入excel文件时,我遇到了一个问题。尽管只有在使用dplyr软件包中的函数创建数据帧时,才会出现此问题。当我使用基函数时,没有问题。下面是一个简单的例子 首先,样本数据: library(dplyr) library(xlsx) month <- c('Julio','Diciembre','Diciembre','Agosto','Noviembre', 'Diciembre', 'Junio','Sep

当我试图使用
xlsx
软件包中的函数
write.xlsx
将数据框写入excel文件时,我遇到了一个问题。尽管只有在使用
dplyr
软件包中的函数创建数据帧时,才会出现此问题。当我使用基函数时,没有问题。下面是一个简单的例子

首先,样本数据:

library(dplyr)
library(xlsx)
month <- c('Julio','Diciembre','Diciembre','Agosto','Noviembre',
         'Diciembre', 'Junio','Septiembre','Agosto','Julio')

irrelevant_column <- rep(1,10)

df <- as.data.frame(cbind(irrelevant_column, month)) 

是否有解决方案,或者是因为
xlsx
dplyr
不兼容?

遇到了这个问题,并使用as.data.frame()将组_中的tible输出指定为df()%%>%summary()。

如果删除
month2,这很容易,)这是否回答了您的问题?
month1  <- table(df$month, df$irrelevant_column)
month1  <- prop.table(month1  , 2)
month1  <- as.data.frame.matrix(month1  )
write.xlsx(month1 ,  file="month1.xlsx")
month2<- count(df, month)
month2<- mutate(month2, porc = n / sum(month2[, 2]))
month2<- as.data.frame.matrix(month2)
write.xlsx(month2,  file="month2.xlsx")
Error in .jcall(cell, "V", "setCellValue", value) : 
  method setCellValue with signature ([Ljava/lang/String;)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