【问题标题】:Is there a function in R to rename rows by groups with increasing numbersR中是否有一个函数可以按数量增加的组重命名行
【发布时间】:2021-04-01 16:51:27
【问题描述】:

我有一个非常简单的数据框 [36, 4],我想重命名一列的行: 见附图中的“Ab_type”列

我想按 4 组重命名“Ab_type”列的 36 行(例如 Ab1_1、Ab1_2、Ab1_3、Ab1_4、Ab2_1、Ab2_2、Ab2_3、Ab2_4、....Isotype_1、Isotype_2、Isotype_3、Isotype_4 )。

你有什么建议吗? 我对编码完全陌生。 非常感谢。

enter image description here

【问题讨论】:

  • 请阅读r标签页顶部的说明,特别是请注意,图像不应该作为呈现数据的唯一方式,因为它使其他人难以复制它。

标签: r rename rows


【解决方案1】:

我们可以使用

df1$Ab_type <- sub("-", "", sub("-[^-]+$", "", df1$Ab_type))
df1$Ab_type <- with(df1, paste0(Ab_type, "_", 
     ave(seq_along(Ab_type), Ab_type, FUN = seq_along)))

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多