Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

problems with loop in R

  • 28-10-2011 12:10PM
    #1
    Registered Users, Registered Users 2 Posts: 26


    Hi
    i am looking for some help in figuring out the problem with my R script, i'm trying to look through a set of paired values in a matrix and randomize them. the following is what i've written


    for (i in 1:29412) for (j in 1:899/2) #the second length in j is halved for a reason seen later in the script
    {
    if(ped[i,2*j-1]==ped[i,2*j]) #this selects my columns in pairs
    next
    else if (random==1) #random = sample(1:0,1)
    ped[i,2*j-1]->x ; ped[i,2*j]->y ; y->ped[i,2*j-1] ; x->ped[i,2*j] #ped is my martix of interest
    else break
    }

    the following is the error i'm getting


    > for (i in 1:29412) for (j in 1:899/2)
    + {
    + if(ped[i,2*j-1]==ped[i,2*j])
    + next
    + else
    + if (random==1)
    + ped[i,2*j-1]->x ; ped[i,2*j]->y ; y->ped[i,2*j-1] ; x->ped[i,2*j]
    + else break
    Error: unexpected 'else' in:
    "ped[i,2*j-1]->x ; ped[i,2*j]->y ; y->ped[i,2*j-1] ; x->ped[i,2*j]
    else"
    > }
    Error: unexpected '}' in "}"
    >


Advertisement