Re: [問題] 輸出的結果,如何完整貼到文件呢?(求救)
我用writeLines試著寫了一個, 應該是可以符合你的需求, 你可以再嘗試最佳化~
#示範用data frame
library(dplyr)
x <- c('A', 'B', 'C')
y <- c(1, 2, 3)
df <- data.frame(x, y) %>%
mutate_all(as.character)
#先設定一個檔案 (檔名改word也可以), 等會writeline可以寫入
text_print <- file("text_print.txt", open="wt")
ch.col<- names(df)[sapply(df, is.character)]
for (name in ch.col)
{
line1 <- sprintf("Unique value for %s is",name)
line2 <- unique(df[[name]])
writeLines(line1, con = text_print, sep = "\n", useBytes = FALSE)
writeLines(line2, con = text_print, sep = " ", useBytes = FALSE)
writeLines("\n", con = text_print, sep = "\n", useBytes = FALSE)
}
close(text_print)
#開啟檔案就可以看到寫入的資料了
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.173.79.18
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1541236608.A.A6C.html
推
11/03 21:39,
6年前
, 1F
11/03 21:39, 1F
→
11/03 22:19,
6年前
, 2F
11/03 22:19, 2F
※ 編輯: TreeMan (1.173.79.18), 11/03/2018 22:19:50
推
11/04 09:50,
6年前
, 3F
11/04 09:50, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章