Skip to content
Prev 278 / 1559 Next

R GUI is puzzling me

Dear Sir/Madam,

I have a data.frame which consist of two columns and several rows. The
values of 2nd column can be either TRUE or FALSE.
I want to save all the value of first column in another variable whose
corresponding row in second column have value TRUE.

Please consider the following example:

#currently i am doing this.
date <- 0
j <- 1
for (i in 1:nrow(final))
{
    if(final[i,2] == TRUE)
    {
        date[j] <- final[i,1]
        j <- j+1
    }
}

Is there any efficient method (single line code) to do the same?