[R] How do you use agrep inside a loop

Rui Barradas ruipbarradas at sapo.pt
Tue Dec 11 11:55:50 CET 2012


Hello,

And another error in line 2. It should be

for(j in (i+1):length(test1))


Hope this helps,

Rui Barradas

Em 11-12-2012 07:54, Pascal Oettli escreveu:
> Hi,
>
> There is a mistake in the first line. It should be:
> > for(i in 1:(length(test1)-1))
>
> Regards,
> Pascal
>
>
> Le 11/12/2012 16:01, surekha nagabhushan a écrit :
>> Hi all.
>>
>> This is my first message at R-help...so I'm hoping I have some 
>> beginner's
>> luck and get some good help for my problem!
>>
>> FYI I have just started using R recently so my knowledge of R is pretty
>> preliminary.
>>
>> Okay here is what I need help with - I need to know how to use agrep 
>> in a
>>   for loop.
>>
>> I need to compare elements of a vector of names with other elements 
>> of the
>> same vector.
>>
>> However if I use something like this:
>>
>> for(i in 1:length(test1)-1)
>> {
>>    for(j in i+1:length(test1))
>>    {
>>    result[[i]][j] <- agrep(test1[i], test1[j], ignore.case = TRUE, 
>> value =
>> TRUE, max.distance = 0.1)
>>    }
>>
>> }
>>
>> I get an error message saying - invalid 'pattern' argument. -* Error in
>> agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, 
>> max.distance =
>> 0.1) : *
>> *  invalid 'pattern' argument*
>>
>> Test 1 being - c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new 
>> Mumbai",
>> "Thana", "Surekha", "Thane(w)", "surekhaN")
>>
>> This is the first time I'm using agrep, I do not understand how it works
>> fully...
>>
>> Kindly help...
>>
>> Thank you.
>>
>> Su.
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>>
>
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list