having issue with for loop

I'm trying to get the square of prime numbers between 1:10 using for loop as below:

sq_pr_no=function()
{
sq_pr_no=c()
for (i in 1:10)
{
for (p in 2:i-1)
{
if (i%%p==0)
{
sq_pr_no=c(sq_pr_no,i^2)
}
}
}
}

and I'm getting error as follows
Error in if (i%%p == 0) { : missing value where TRUE/FALSE needed

Please help me to solve this

Thanks and Regards,
Arun kumar

the first time through i has value 1 and what is the range of p ?
p in 2:1-1 i.e. 2:0 , ie. 2 then 1 then 0
this is probably not desired loop.
when 1 %% 0 is encountered this is NaN and cant be evaluated against ==0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.