Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204847

how to list dataframes with characteres between patterns

$
0
0

How do we list files which has letters between patterns in their names? Lets say we have several dataframes like AgI_M.txt, AgI_PQ.txt, AgII_M.txt, AgII_PQ.txt, AgIII_M.txt, AgIII_PQ.txt, AgN_M.txt, AgN_PQ.txt, CoI_M.txt, CoI_PQ.txt, CoN_M.txt, CoN_PQ.txt, .... And we want to make a list with those who start with "Ag" and ends with "_M.txt". I need to know what do we put in the middle of the pattern definition please. Until now i guess it should be something like

Ag_files<-list.files(path="",
                     pattern="Ag\\ \\_M.txt") #what do we do put in the middle?

Than... Do i name them (dataframes in the list) using their original names like this?

Ag_data<-lapply(Ag_files, read.table)
names(Ag_data)<-gsub(""Ag\\ \\_M.txt"","", Ag_files)

Thanks!


Viewing all articles
Browse latest Browse all 204847

Trending Articles