how to extract the first number from each string in a vector in R?

后端 未结 7 1162
醉话见心
醉话见心 2020-12-18 10:53

I am new to regex in R. Here I have a vector where I am interested in extracting the first occurance of a number in each string of the vector .

I have a vector calle

7条回答
  •  清酒与你
    2020-12-18 11:10

    R's regmatches() method returns a vector with the first regex match in each element:

    regmatches(shootsummary, regexpr("\\d+", shootsummary, perl=TRUE));
    

提交回复
热议问题