Skip to content
Prev 371271 / 398530 Next

Optimize code to read text-file with digits

On 8 September 2017 at 11:25, PIKAL Petr <petr.pikal at precheza.cz> wrote:

            
Good idea.
[...]
here you need to read values as character variables
Yes. That's what I am looking for.
Do I still need to loop through all lines?
It is maybe even slower now.

numbers <- vector('numeric')
for (i in 1:nrows(lines)) {
  numbers <- c(numbers, as.numeric(unlist(strsplit(as.
character(lines[i,]),""))))
}
A numeric vector of length 1 million. Each element should be one digit.
Thanks.
/Martin