作者nina8598 (Nina)
看板R_Language
標題[問題] csv儲存格存成記事本txt檔
時間Wed Feb 28 13:30:51 2018
[問題類型]:
程式諮詢(我想用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://webptt.com/m.aspx?n=bbs/R_Language/M.1519795854.A.45C.html
1F:推 sw52099: for(i in 1:length(data$message)){ 02/28 13:41
2F:→ sw52099: path = paste0('~/your path/', i, '.txt') 02/28 13:41
3F:→ sw52099: write.table(data$message[i], path) 02/28 13:41
4F:→ sw52099: } 02/28 13:41
5F:→ celestialgod: 樓上的write.table改成write可能比較合適 02/28 13:59
6F:→ nina8598: 謝謝各位~~問題解決了!我最後是用write.table這個函數, 02/28 14:54
7F:→ nina8598: 因為我用write的話輸出的記事本內容是"1" "2" "3"..., 02/28 14:54
8F:→ nina8598: 不是我要的message內容,還是謝謝大家! 02/28 14:54
9F:→ clansoda: 我比較好奇創造出三萬個TXT會怎麼樣 02/28 15:02
10F:→ celestialgod: 那是因為write的輸出跟輸入跟write.table相反= =" 02/28 15:27
11F:→ celestialgod: 我記錯了@@ 02/28 15:28
12F:→ celestialgod: 喔喔,因為data$message是factor阿... 02/28 15:28
13F:→ celestialgod: 我會推薦write原因是因為write.table會輸出 02/28 15:29
14F:→ celestialgod: rownames跟colnames,write就可以直接避免掉了 02/28 15:29
15F:推 sw52099: 原來如此,謝謝c大指教! 03/01 13:54