2015-12-23 14 views
12

Il dataframe è visibile senza alcun errore. Ma quando lo stesso è stampato usando la fucnizione write.xlsx del pacchetto XLSX, dà l'errore.Errore nella stampa data.frame in excel utilizzando il pacchetto XLSX in R

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

La dput del data.frame assomiglia:

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) 

aiuto gentile per risolvere questo errore.

+0

Cosa si intende per "quando lo stesso viene stampato utilizzando la funzione write.xlsx"? Stai facendo 'print (write.xlsx (...))'? O è l'errore solo quando chiami 'write.xlsx (...)'? Potete fornire un esempio riproducibile? –

+0

L'output viene stampato utilizzando: write.xlsx (q1, file = paste0 (indirizzo file "," _ 6 ",". Xlsx "), sheetName =" Foglio1 ", col.names = TRUE, row.names = FALSE, append = TRUE) –

+0

Puoi fornire un [esempio riproducibile] (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Inoltre, il tuo "dput dei dati". frame "non assomiglia a qualcosa che' dput (my.dataframe) 'potrebbe produrre, puoi guardare' class (my.dataframe) 'e confermare che la classe (solo) è" data.frame "? –

risposta

25

Ancora nessuna esempio riproducibili, ma dalla tua class(q1) sembra che q1 è una tbl_df (il tipo di dataframe che il pacchetto dplyr produce), mentre write.xlsx aspetta una data.frame.

Provare a dare write.xlsx un semplice data.frame come previsto. per esempio.

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

Ecco un reproducible example (cioè si può copiare e incollare nella tua sessione di R per riprodurre il 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. 

Ora proviamo risolvere il problema facendo in modo che write.xlsx ottiene un data.frame, non un tbl_df!

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

Sembra che ci sia un bug con il formato Data/Ora della prima colonna (Timestamp). Se converti la prima colonna in carattere, dovrebbe funzionare. così, si può cambiare la vostra prima colonna a

q1[,1] <- as.character(q1[,1]) 

e riprovare ...

0

Trovo questo accade quando il raggruppamento variabili con dplyr. Se si termina una catena con%>% ungroup() sembra risolvere

Problemi correlati