При условии, что ваш текстовый файл quote.txt
в рабочем каталоге.
R base решение: разделить его 2 раза: (1) на \n\n
и (2) на ---
, затем объединить в фрейм данных.
quote <- readLines("quote.txt")
quote <- paste(quote, collapse = "\n")
DF <- strsplit(unlist(strsplit(quote, "\n\n")), "---")
DF <- data.frame(text= trimws(sapply(DF, "[[", 1)),
source = trimws(sapply(DF, "[[", 2)))
Вывод
DF
# text
# 1 DIAGRAMS are of great utility for illustrating certain questions of vital statistics by\nconveying ideas on the subject through the eye, which cannot be so readily grasped when\ncontained in figures.
# 2 To give insight to statistical information it occurred to me, that making an\nappeal to the eye when proportion and magnitude are concerned, is the best and\nreadiest method of conveying a distinct idea.
# 3 Regarding numbers and proportions, the best way to catch the imagination is to speak to the eyes.
# 4 The aim of my carte figurative is to convey promptly to the eye the relation not given quickly by numbers requiring mental calculation.
# source
# 1 Florence Nightingale, Mortality of the British Army, 1857
# 2 William Playfair, The Statistical Breviary (1801), p. 2
# 3 William Playfair, Elemens de statistique, Paris, 1802, p. XX.
# 4 Charles Joseph Minard