[英]How can I remove certain part of row names in data frame
I have a data set with the following format: 我有一个具有以下格式的数据集:
ID | Value
-------------------------- | -------------------------------
AAA1|404744 | 1.7554
ANKHD1-EIF4EBP3|404734 | 0.5174
HLA-B|3106 | 11.7659
HLA-A|3105 | 18.0851
What I want is removing certain part of the row names like this: 我想要的是删除行名称的某些部分,如下所示:
ID | Value
--------------------- | -------------------------------
AAA1 | 1.7554
ANKHD1-EIF4EBP3 | 0.5174
HLA-B | 11.7659
HLA-A | 18.0851
Thanks a lot! 非常感谢!
We can do this with sub
. 我们可以用
sub
来做到这一点。 Match the |
匹配
|
(a metacharacter implies or
- so either escape \\\\|
it or place it in brackets to get the literal character) followed by characters ( .*
) and replace it with blank ( ""
) (一个元字符暗示
or
-因此,请转义\\\\|
或将其放在方括号中以获得原义字符),然后是字符( .*
),并将其替换为空白( ""
)
df$ID <- sub("[|].*", "", df$ID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.