I would use directly readLines()
(since you don't need a data.frame), then strsplit()
to slit each line into its components, and unlist()
if you want the final format as a vector (FJCC's paste()
being the way to go if you want the final data as a string).
# FJCC's fake data
original <- c(paste(rep(1:3, 10),collapse = ""),
paste(rep(2:4, 10),collapse = ""),
paste(rep(3:5, 10),collapse = ""),
paste(rep(4:6, 10),collapse = ""))
original
#> [1] "123123123123123123123123123123" "234234234234234234234234234234"
#> [3] "345345345345345345345345345345" "456456456456456456456456456456"
writeLines(original, "saved_pi.txt")
readLines("saved_pi.txt") |>
strsplit(split = "") |>
unlist() |>
as.integer()
#> [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 2 3 4 2 3 4 2
#> [38] 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 3 4 5 3 4 5 3 4 5 3 4 5 3 4
#> [75] 5 3 4 5 3 4 5 3 4 5 3 4 5 3 4 5 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6
#> [112] 4 5 6 4 5 6 4 5 6
Created on 2022-03-13 by the reprex package (v2.0.1)