Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

problems with loop in R

Options
  • 28-10-2011 12:10pm
    #1
    Registered Users 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