Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 views
in Technique[技术] by (71.8m points)

r - Unimplemented type list when trying to write.table

I have the following data.table (data.frame) called output:

> head(output)
        Id                                           Title IsProhibited
1 10000074                             Renault Logan, 2005            0
2 10000124              ?ê?à??ê?? ??ì?ù?íè?, 345 ì<U+00B2>            0
3 10000175                                          ?ó-???            0
4 10000196             3-ê êaàeòèeà, 64 ì<U+00B2>, 3/5 yò.            0
5 10000387        Samsung galaxy S4 mini GT-I9190 (÷?eí?é)            0
6 10000395 êàeòèíà ""êe?ì. ??????ê àe?ìàò"" (????ò, ìà???)            0

I am trying to export it to a CSV like so:

> write.table(output, 'output.csv', sep = ',', row.names = FALSE, append = T)

However, when doing so I get the following error:

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol,  : 
unimplemented type 'list' in 'EncodeElement'
In addition: Warning message:
In write.table(output, "output.csv", sep = ",", row.names = FALSE,  :
  appending column names to file

I have tried converting the Title to a string so that it is no longer of type list like so:

toString(output$Title)

But, I get the same error. My types are:

> class(output)
[1] "data.frame"
> class(output$Id)
[1] "integer"
> class(output$Title)
[1] "list"
> class(output$IsProhibited)
[1] "factor"

Can anyone tell me how I can export my data.frame to CSV?

Another strange thing that I've noticed, is that if I write head(output) my text is not encoded properly (as shown above) whereas if I simply write output$Title[0:3] it will display the text correctly like so:

> output$Title[0:3]
[[1]]
[1] "Renault Logan, 2005"

[[2]]
[1] "Складское помещение, 345 м2"

[[3]]
[1] "Су-шеф"

Any ideas regarding that? Is it relevant to my initial problem?

Edit: Here is my new output:

Id  Title   IsProhibited    
10000074    Renault Logan, 2005 0   
10000124    D?DoD?D°D′?DoD?Dμ D?D?D?Dμ?‰DμD?D?Dμ, 345 D?<U+00B2>    0   
10000175    D???-??Dμ?? 0   
10000196    3-Do DoD2D°?€??D??€D°, 64 D?<U+00B2>, 3/5 ???.  0   
10000387    Samsung galaxy S4 mini GT-I9190 (???‘?€D???D1)  0   
10000395    D?D°?€??D?D?D° "D??€??D?. D?D??DμD?D?Do D?€D?D?D°??"" (?…D?D????     D?D°?D?D?)"    0
10000594    D?D°D????D? 25 ?D?  0   
10000612    1-Do DoD2D°?€??D??€D°, 45 D?<U+00B2>, 6/17 ???. 0   
10000816    D“D°?€D°D?, 18 D?<U+00B2>   0   
10000831    D?D?D°????Dμ    0   
10000930    D?D°?€D±???€D°??D??€?? D?-22D?, D?-22D“ D??? D3D°D· 21 D? D3D°D· 51 0   

Notice how line ID 10000395 is messed up? It seems to contains quotes of it's own which are messing up the CSV. How can I fix that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do this, irrespective of how many columns you have:

df <- apply(df,2,as.character)

Then do write.csv.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...