使用R中的Match函数查找“首次出现" [英] Finding 'first occurrence' using Match Function in R

查看:75
本文介绍了使用R中的Match函数查找“首次出现"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对'R'和'Stackoverflow'是陌生的,所以请原谅我这个难以置信的基本问题.我试图在数据集中找到第一位女性的索引".

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.

代码快照

我的整体数据集称为自行车",因此我首先认为分配一个新的性别矢量是个好主意...

My overall dataset is called 'bike', so first I thought it would be a good idea to assign a new vector of just the genders...

bike$genders

然后我尝试使用该功能:

Then I tried using the function:

match(1, genders)
match(F, genders)

两者都不起作用!我知道这应该而且应该相对简单一些,但是我才刚刚起步,非常感谢您的帮助.

Neither of which worked! I know this is and should be relatively simple but I'm just starting out so I really appreciate your help.

推荐答案

可能最直接的方法是使用match("F", bike[,"genders"] 将返回第一个匹配项的索引.

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

这篇关于使用R中的Match函数查找“首次出现"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆