我有一个非常简单的数据框36,4,我想重命名其中一列的行:请参阅所附图像中的列“Ab_type
我想将列"Ab_type“的36行按4组重命名(例如,Ab1_1,Ab1_2,Ab1_3,Ab1_4,Ab2_1,Ab2_2,Ab2_3,Ab2_4,....Isotype_1,Isotype_2,Isotype_3,Isotype_4)。
你有什么建议吗?我对编程完全陌生。在此之前,非常感谢您。
发布于 2021-04-01 16:53:55
我们可以使用
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)))
https://stackoverflow.com/questions/66908603
复制