2017-02-19 64 views
1

我有一個〜4GB +的數據集。打印一份清單的大名單

結構是

UniqueID Tags 
1   1, 37, 284 
2   1, 284 
3   234, 456, 789 
... 

我想寫這樣一個文件,但是它給我,因爲

typeof(structure) = list 

typeof(structure$Tags) = list 

我希望問題將其寫入表格中,如圖所示,其中1列是UniqueID,下一列是第二列表打印出來。

當我試圖寫它目前使用

write.table(structure, output_file, sep="\t", row.names=FALSE,col.names=TRUE,quote=FALSE) 

我得到

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

這一點我敢肯定,是因爲我的表內有它的列表。

編輯:我要補充,我試圖做 結構$標籤=膏(結構$標籤,崩潰= 「」)

但後來我的結果保存的格式

"c(Tag1, Tag2, ..., TagN)" 
"c(Tag1, Tag284, ...)" 
+1

您是否嘗試通過'writeRDS'將其寫入'rds'文件? - 看看這裏:https://stat.ethz.ch/R-manual/R-patched/library/base/html/readRDS.html – Rentrop

+0

你想讀取數據到另一個程序或只是保存這樣它可以很容易地加載回R? – Dason

回答

0

你可以創建一個新的數據框並寫入它。

tagLists <- sapply(structure$tags, paste, collapse = ",") 
df <- data.frame(unique_ids = structure$unique_ids, tags = tagLists)