How to import numbered files in R

I have several files named xdata.asciiand xis a number. How can I import all the files with names of 1data.ascii, for example 100data.ascii. I have other files .asciithat have a different name and do not want to import them.

+4
source share
1 answer

We can use list.filesto get all the template files

files <- list.files(pattern = "\\d+data\\.ascii", full.names = TRUE)

Then read the files by going through lapplytolist

lst <- lapply(files, read.csv)
+3
source

Source: https://habr.com/ru/post/1677078/


All Articles