看板 R_Language 關於我們 聯絡資訊
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 新手(沒寫過程式,R 是我的第一次) [問題敘述]: 有個csv檔(約三萬筆資料) no id time message 1 12345 2016-07-07T02:07:15+0000 Sounds great! 2 67890 2016-07-07T02:12:14+0000 Good good eat! 3 66666 2016-07-07T02:28:44+0000 I like it. . . . . . . . . 30000 34567 2017-11-01T09:47:53+0000 The end~ 我想做的是,把message那欄的每個儲存格都存成一個txt檔, 例如 Sounds great! >> 1.txt Good good eat! >> 2.txt I like it. >> 3.txt . . The end~ >> 30000.txt 請問應該怎麼做? 感謝各位大神了~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.8.152.63 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1519795854.A.45C.html
sw52099: for(i in 1:length(data$message)){ 02/28 13:41
sw52099: path = paste0('~/your path/', i, '.txt') 02/28 13:41
sw52099: write.table(data$message[i], path) 02/28 13:41
sw52099: } 02/28 13:41
celestialgod: 樓上的write.table改成write可能比較合適 02/28 13:59
nina8598: 謝謝各位~~問題解決了!我最後是用write.table這個函數, 02/28 14:54
nina8598: 因為我用write的話輸出的記事本內容是"1" "2" "3"..., 02/28 14:54
nina8598: 不是我要的message內容,還是謝謝大家! 02/28 14:54
clansoda: 我比較好奇創造出三萬個TXT會怎麼樣 02/28 15:02
celestialgod: 那是因為write的輸出跟輸入跟write.table相反= =" 02/28 15:27
celestialgod: 我記錯了@@ 02/28 15:28
celestialgod: 喔喔,因為data$message是factor阿... 02/28 15:28
celestialgod: 我會推薦write原因是因為write.table會輸出 02/28 15:29
celestialgod: rownames跟colnames,write就可以直接避免掉了 02/28 15:29
sw52099: 原來如此,謝謝c大指教! 03/01 13:54