An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/3281be54/attachment.pl>
How do you use agrep inside a loop
11 messages · surekha nagabhushan, Pascal Oettli, Rui Barradas
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/f1fd0c49/attachment.pl>
Hello, Probably because 'result' doesn't have the expected size/number of dimension. How do you create it? Regards, Pascal Le 11/12/2012 19:46, surekha nagabhushan a ?crit :
Thank you for that Pascal.
I changed this bit to the following:
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
for(j in i+1:length(test1))
{
result[[i]][j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value = TRUE, max.distance = 0.1)
}
}
And now I get the error - Error in result[[i]][j - i] <- agrep(test1[i],
test1[j], ignore.case = TRUE, :
replacement has length zero
What does this mean?
On Tue, Dec 11, 2012 at 1:24 PM, Pascal Oettli <kridox at ymail.com
<mailto:kridox at ymail.com>> wrote:
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 <mailto:R-help at r-project.org> mailing list
https://stat.ethz.ch/mailman/__listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide
http://www.R-project.org/__posting-guide.html
<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/b1498d97/attachment.pl>
Hello, Right, I didn't notice. Apologies. Pascal Le 11/12/2012 19:55, Rui Barradas a ?crit :
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.
Hello,
See if this is it. You must reinitialize 'result_vector' just before the
loop that constructs it.
test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1)){
result_vector <- vector()
for(j in (i+1):length(test1)){
tmp <- agrep(test1[i], test1[j],
ignore.case = TRUE, value = TRUE,
max.distance = 0.1)
if(length(tmp) > 0) result_vector[j-i] <- tmp
}
result[[i]] <- result_vector
}
result
Hope this helps,
Rui Barradas
Em 11-12-2012 11:23, surekha nagabhushan escreveu:
Pascal,
result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
for(j in (i+1):length(test1))
{
result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
}
result[[i]]<- result_vector
}
I'm not sure what the problem is with the dimension/length of result which
is a list. But I just use the second line: result <- vector("list",
(length(test1)-1))
What am I missing?
Thank you Rui Barradas.
On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
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<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <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<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/300cba03/attachment.pl>
Hello, Inline. Em 11-12-2012 12:04, surekha nagabhushan escreveu:
Rui, I have initialized it...doesn't seem to help... result_vector <- vector()
No! This must be just before the loop in 'j'
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
for(j in (i+1):length(test1))
{
result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE, value
= TRUE, max.distance = 0.1)
}
result[[i]]<- result_vector
}
whenever agrep does not find a match it returns character(0), length zero,
do you suppose it has anything to do with that?
Yes, without testing for length zero it throws an error, "replacement has length zero". Hope this helps, Rui Barradas
Thank you. On Tue, Dec 11, 2012 at 5:13 PM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
Hello,
See if this is it. You must reinitialize 'result_vector' just before the
loop that constructs it.
test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",
"Thana", "Surekha", "Thane(w)", "surekhaN")
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1)){
result_vector <- vector()
for(j in (i+1):length(test1)){
tmp <- agrep(test1[i], test1[j],
ignore.case = TRUE, value = TRUE,
max.distance = 0.1)
if(length(tmp) > 0) result_vector[j-i] <- tmp
}
result[[i]] <- result_vector
}
result
Hope this helps,
Rui Barradas
Em 11-12-2012 11:23, surekha nagabhushan escreveu:
Pascal,
result_vector <- vector()
result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1))
{
for(j in (i+1):length(test1))
{
result_vector[j-i] <- agrep(test1[i], test1[j], ignore.case = TRUE,
value
= TRUE, max.distance = 0.1)
}
result[[i]]<- result_vector
}
I'm not sure what the problem is with the dimension/length of result which
is a list. But I just use the second line: result <- vector("list",
(length(test1)-1))
What am I missing?
Thank you Rui Barradas.
On Tue, Dec 11, 2012 at 4:25 PM, Rui Barradas <ruipbarradas at sapo.pt>
wrote:
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<https://stat.ethz.ch/mailman/**listinfo/r-help> <https://stat.**ethz.ch/mailman/listinfo/r-**help<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <http://www.R-project.org/**posting-guide.html<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<https://stat.ethz.ch/mailman/**listinfo/r-help> <https://stat.**ethz.ch/mailman/listinfo/r-**help<https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html <http://www.R-project.org/**posting-guide.html<http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121213/0f06a3b5/attachment.pl>