# importing a long .txt containing only numbers

hello
i have here a `pi.txt` file containing n=1.000.000 digits of Pi.
i would like to import it as a vector of n elements
but which instruction could i use ?
`read.csv("pi.txt",csv="")` doesn't do the job…

``````mynumdigs <- strsplit(
con =
file("lots_of_numbers.txt")
),
split = ""
)[[1]] |> as.integer()``````

thanks very much

not understood the [[1]] nor the |>
...

but works very fine

how could i count the number of sequences "14" for example ?
maybe str_count but it would need to transform the vector into a big string… ?

``````(vec_of_digits <- str_c(1:1000, collapse = "") |>
str_split("") |>
unlist() |>
as.integer())

library(dplyr) # for the useful dplyr::lag
#but could write your own function

(t_f_14 <- lag(vec_of_digits) == 1 &
vec_of_digits == 4)

table(t_f_14)
# there are 31 '14's
# you can stop here if you only wanted to count them

# Their end positions :
(pos_14 <- which(t_f_14))

# validate :
(extracts <- lapply(pos_14, \(x)c(
vec_of_digits[x - 1],
vec_of_digits[x]
)))``````

thanks i have done this :

``````
library(dplyr) # for the useful dplyr::lag @ lead
pi_tout <- strsplit(
split = ""
)[[1]] |> as.integer()

length(pi_tout)

#chiffres isoles
table(pi_tout)

#n-uplets 000..00,111..11
n <- 7# n doit etre superieur ou egal a deux
for (i in 0:9){
les_ii <- (pi_tout==i) #vecteur de booleens
pi_tout_glissant <- pi_tout
for (combien in 1:(n-1)){
les_ii <- (les_ii & (pi_tout_glissant==i))
}
les_ii <- les_ii[!is.na(les_ii[])]
cat(sum(les_ii),"occurrences de ",n,"fois le chiffre ",i,"\n")
}

it works

thanks very much for deblocking
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.