简体   繁体   English

R的正则表达式

[英]Regular expression with R

> name = '645te5.78d'

I am looking for a function that can get rid of the dot and anything that follows in my variable name . 我正在寻找一个可以消除点号和变量name后面的内容的函数。

> new_fun(name)
> name
'645te5'

sub应该工作:

sub('\\..*', '', name)

If that is a general case that 如果那是一般情况

There exist only one dot and you want to get the first part. 仅存在一个点,您想获得第一部分。 Maybe you strsplit instead. 也许您strsplit

unlist(strsplit(name, '\\.'))[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM