简体   繁体   English

如何删除数据框中行名称的某些部分

[英]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.

相关问题 如何删除数据框一栏中的部分名称? - how can I remove part of a names in one column of a data frame? 如何根据 R 中数据框中的某些列和行信息删除唯一行 - How do I remove unique rows based on certain column and row information in a data frame in R 我有一个从数据帧中提取的子集矩阵,如何获得相应的行名? - I have a subset matrix extracted from a data frame, how can I get the corresponding row names? 如何根据另一个对象的row.names对data.frame(表)进行排序 - How can I sort a data.frame (table) based on another object's row.names 如何在循环中将列表的列名更改为每个数据框的第一行? - How can I change the column names of a list to the first row of each data frame in a loop? 如何重命名部分数据框中的列名? - How to rename column names in part of data frame? 如何累积将数据帧的行累加到一定数量,然后从下一行重新开始? - How can I cumulatively add rows of a data frame until a certain number, then start over at next row? row.names(df[c(6193,7812),])- 如何在 R 中显示 data.frame 的某些 row.names? - row.names(df[c(6193,7812),])- How to diplay certain row.names of a data.frame in R? 如何删除数据框列中的部分字符 - How to remove part of characters in data frame column 如何在数据框中重复行的一部分 - How to repeat part of a row in a data frame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM