it did help to create the separate vectors. The problem is, I would like to continue working with each vector on its own and make some further analysis. For that i need to allocate each vector in the filePatterns a unique name, which I just can't do. I'm not so great in R loops and the help over the net regards for loops in R is quite rare. I'm really thankful for every help. Mit freundlichen Grüßen / Best Regards Assa Yeroslaviz "Richard Pugh" <rpugh@mango-solutions.com> 09.10.2008 14:06 An <assa.yeroslaviz@bayercropscience.com> Kopie Thema FW: [R] R loops Hi Assa, I happened to have some code on my screen that does exactly what you want: myDir <- "D:\\Temp" allFiles <- list.files(myDir) somePatterns <- c("xls", "csv", "sas7bdat") filePatterns <- lapply(somePatterns, function(pat, files) files[grep(pat, files)], files=allFiles) cat(paste("\n", somePatterns, ": ", sapply(filePatterns, paste, collapse=", "), sep="")) Hope this helps, Rich. mangosolutions S & R Consulting & Training -----Original Message----- From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org] On Behalf Of assa.yeroslaviz@bayercropscience.com Sent: 09 October 2008 12:56 To: r-help@r-project.org Subject: [R] R loops hello everybody, I have a directory with over 3000 files with different names. I would like to make some vectors with the file names which are belong together. I'm trying to do it with a for loop in R: SF <- c("ad", "cd", "cer", "stress", "salty", "PC", "high", "transfer", "cold", "heat") # the pattern to look for names(SF) <- as.vector(SF) for (i in 1:length(SF)){ write(names(SF)[i], "") for (j in 1:length(SF)) {list[j] <- grep(names(SF)[j], list.files(),value=TRUE) #character vector with the specified stress factor } } but all I'm getting is this Error in list[j] <- grep(names(SF)[j], list.files(), value = TRUE) : object of type 'builtin' is not subsettable I would like the loop to make in each round a list of the files with the pattern in the directory I'm looking in. what am i doing wrong? If I doing it for each element I'm getting the correct list. THX for the help Best Regards Assa Yeroslaviz [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]