Not quite sure if I understand you. list.files() simply returns a character vector(not a list). You can simply use a vector index to select whatever file you wish to read. So if your desired filename is the 5th element of filelist above, something like
myfile <- read.table(filename[5], ...) You can also use regular expressions to choose a bunch of files that have some common signature to their names that you can read in simultaneously using your "filelist" vector of names via something like: myfiles <- lapply(grep("weath", filelist, value = TRUE), \(x) read.table(x,...)) ### Note that the result of lapply *is* a list, so use list indexing for extraction from myfiles. You can also choose files to read interactively (via a GUI interface) using file.choose() instead of using list.files() if you prefer to do it that way. Cheers, Bert On Wed, Nov 6, 2024 at 8:25 AM Sibylle Stöckli via R-help < r-help@r-project.org> wrote: > Dear community > > To import multiple .dat weather files I am using list.files(). > I intend to use the R package “ClimInd” to calculate different > agroclimatic indicators. > > Question: Is there another solution to import multiple .dat files so that > I can select elements from the list, e.g. one specific weather file > (example AAR_DailyWeather)? > > > # Import multiple .dat files weather data > filelist <- list.files(path = > "O:/Data-Work/……./Daten_RA-MeteoCH_1990-2021", pattern='*.dat', all.files= > T, full.names= T) > W <- lapply(filelist, function(x) read.table(x, header = TRUE, sep = "", > colClasses = "numeric", comment.char = "")) > W[[1]] > > > dd(data = W[[1]]$Precip, time.scale = W[[1]]$year) > Fehler in W[[1]]$year : $ operator is invalid for atomic vectors > > Kind regards > Sibylle > > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.