Finding 'first occurrence' using Match Function in R

前端 未结 2 673
故里飘歌
故里飘歌 2021-01-24 00:00

I am new to \'R\' and \'Stackoverflow\' so forgive me for the incredibly basic question. I\'m trying to find the \'index\' of the first female in my dataset.

Code Snaps

相关标签:
2条回答
  • 2021-01-24 00:06

    If you want to know the rows#, this should give you the rows, with their numbers printed to the screen, and you will see the index for rows with it.

    bike[bike$gender=="F",]

    and if you only want the row numbers to set to a vector
    rnam<-row.names(bike[bike$gender=="F",])

    0 讨论(0)
  • 2021-01-24 00:17

    Probably the most direct method would be to use match("F", bike[,"genders"] which will return the index of the first match.

    0 讨论(0)
提交回复
热议问题