Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Export a list into a CSV or TXT file in R

I'm sorry to ask this question. I'm very noob with R. I know there is a lot of threads which are related to the very same problem. I understood that we cannot export a table if one of its elements is a list but I didn't manage to solve my problem though. So, I got a list in R and I want to export it into a CSV or TXT file. Here is the error message that I get when I execute this write.table command :

write.table(mylist,"test.txt",sep=";")

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol,  : 
unimplemented type 'list' in 'EncodeElement'

Here is the first element of my list :

$f10010_1
$f10010_1$mots
 [1] X16               ESPRESSO          TDISC             TASSIMO          
 [5] CARTE             NOIRE             A                 LAVAZZA          
 [9] MALONGO           MIO               MODO              123              
[13] CAPSULES          DOSES             78G               LONG             
[17] SPRESSO           CAFE              120G              CLASSIC          
[21] 104G              128G              AROMATIQUE        INTENSE          
[25] 112G              156G              520G              5X16             
[29] PROMO             TRIPACK           X24               126G             
[33] 16                4X16              APPASSIONATAMENTE APPASSIONATEMENTE
[37] BRESIL            CAPSUL            COLOMBIE          CORSE            
[41] CREMOSAMENTE      DELICATI          DELIZIOSAMENTE    DIVINAMENTE      
[45] DOLCEMENTE        EQI               GRAND             GRANDE           
[49] GT                GUATEMALA         HAITI             INTENSAMENTE     
[53] ITALIAN           MAGICAMENTE       MERE              MOKA78G          
[57] PETITS            PRODUCT           PURSMATIN         RESERVE          
[61] RISTRETO          SOAVEMENTE        STYLE             X36              
64 Levels: 104G 112G 120G 123 126G 128G 156G 16 4X16 520G 5X16 78G ... X36

$f10010_1$nblabel
 [1] 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
[27] 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
[53] 32 32 32 32 32 32 32 32 32 32 32 32
Levels: 32

$f10010_1$Freq
 [1] 18 16 16 15 14 14  9  9  9  9  9  8  8  8  7  7  7  6  5  5  3  3  3  3  2  2
[27]  2  2  2  2  2  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[53]  1  1  1  1  1  1  1  1  1  1  1  1

$f10010_1$pct
 [1] 0.56250 0.50000 0.50000 0.46875 0.43750 0.43750 0.28125 0.28125 0.28125
[10] 0.28125 0.28125 0.25000 0.25000 0.25000 0.21875 0.21875 0.21875 0.18750
[19] 0.15625 0.15625 0.09375 0.09375 0.09375 0.09375 0.06250 0.06250 0.06250
[28] 0.06250 0.06250 0.06250 0.06250 0.03125 0.03125 0.03125 0.03125 0.03125
[37] 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125
[46] 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125
[55] 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125
[64] 0.03125

Thank you all for your help in advance!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I think the most straightforward way to do this is using capture.output, thus;

capture.output(summary(mylist), file = "My New File.txt")

Easy!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...