mercredi 28 juin 2017

How to use if in a for loop in R

I am trying to compute the occurrence of a line in a dataframe, but I don’t the result expected. ps: generaldf is a dataframe, and userid if a column of integer

y<-0

        for(i in seq_len(nrow(generaldf))) 
        {
          if (generaldf$userid==1) 
            y <-y+1
        }

 return(y)

Aucun commentaire:

Enregistrer un commentaire