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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

problems with loop in R

  • 28-10-2011 11:10am
    #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