gpt4 book ai didi

在 R 或 python 中 reshape 表格

转载 作者:行者123 更新时间:2023-12-02 07:59:19 24 4
gpt4 key购买 nike

<分区>

我有一个看起来像这样的表: enter image description here

code to reproduce this dataframe in  R:
ID = c("0", "51", "7", "62", "1","10","5", "79", "62", "10","1","7")
mRNA = c("0", "0", "30", "1", "0", "14", "0", "1", "1", "16", "0", "0")
Centroid = c("d0","d0", "d0", "d0", "d1", "d1","d1", "d1", "d1", "d10", "d10", "d10")
df <- data.frame(ID,mRNA,Centroid)

我想将这些数据重新格式化为如下所示:

enter image description here

到目前为止我已经试过了:

r <- reshape(df, direction = "wide", idvar="Centroid", timevar="ID")

输出看起来接近我想要的,但还没有(我不希望它使用 ID 重命名列)。

enter image description here

我更喜欢 R 中的解决方案,但如果您有 python 中的建议,我也可以尝试一下。非常感谢任何帮助!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com