[R] agrep pmatch recursive???
Broeckling,Corey
Corey.Broeckling at ColoState.EDU
Tue Nov 9 17:36:50 CET 2010
Hello R Helpers,
Business - 64 bit windows 7, R 2.11.1
I am trying to match the character contents of one list, called 'exclude', to those of a second list, called 'dataset'
dataset is a list of file names with folder locations, and looks like this when called:
> dataset
[1] "A/10-10-29a-13.cdf" "A/10-10-29a-14.cdf" "A/10-10-29a-15.cdf" "A/10-10-29a-16.cdf" "A/10-10-29a-17.cdf" .....(about 20
file location/names in this case).....
I also have the 'exclude' list, which looks like this when called:
> exclude
Row.names
1 10-10-29a-13
2 10-10-29a-14
3 10-10-29a-17
4 10-10-29a-18
or
> exclude[,]
[1] "10-10-29a-13" "10-10-29a-14" "10-10-29a-17" "10-10-29a-18"
As you can see, the formats of the file names in the exclude list are different from those in the dataset list. What I want to
do is to match file names in the exclude list to those in the dataset list and remove them to create a subset_dataset, composed
of all the dataset files minus the files in the exclude list. Since the file names are different, it seems that i have to use
a function such as agrep, and have gotten this to work if I feed in individual file names:
> agrep("10-10-29a-13", dataset, value=TRUE, max.distance=0)
[1] "B/10-10-29a-13.cdf"
However, I don't want to do this manually for each file on the exclude list - I want to do so for each character string on the
exclude list. I am not aware of any list options in agrep specifically, and while pmatch takes a list of a match option, it
will not successfully match the partial string:
> pmatch(exclude[,], dataset)
[1] NA NA NA NA
I am still in the process of teaching myself R, so maybe there is something I am missing. I also tried to figure out how to
use the recursive apply functionality, but haven't been able to get that to work. Any suggestions?
Corey
More information about the R-help
mailing list