问题描述
任何人都可以通过Rmelt函数帮助我重塑数据。我试图将df从长到宽转换,但是当我这样做时,我在重塑时会丢失大部分数据。
输入数据
dd <- data.frame(
Time.point = c(4L,4L,2L,6L,4L),CellType = c("IG2","proNeu-2","Multi-Lin-1","DC","MP","eosinophils","IG2","cMoP","preNeu-1","proNeu-2"),CloneID = c("cl","cl","cl1","cl10","cl10")
)
# Time.point CellType CloneID
# 1 4 IG2 cl
# 2 4 proNeu-2 cl
# 3 2 Multi-Lin-1 cl
# 4 6 DC cl1
# 5 4 MP cl1
# 6 4 eosinophils cl1
# 7 6 IG2 cl10
# 8 6 cMoP cl10
# 9 6 preNeu-1 cl10
# 10 4 proNeu-2 cl10
预期结果
desired <- data.frame(
CloneID = c("cl","cl1"),Timepoint2 = c("Multi-Lin-1","eosinophils|MP"),Timepoint4 = c("IG2|proNeu-2",NA),Timepoint6 = c(NA,"DC")
)
# CloneID Timepoint2 Timepoint4 Timepoint6
# 1 cl Multi-Lin-1 IG2|proNeu-2 <NA>
# 2 cl1 eosinophils|MP <NA> DC
我使用的代码
nt = reshape(data=nt,idvar="CloneID",v.names = "CellType",timevar = "Time.point",direction="wide")```
Error : Warning messages:
1: In reshapeWide(data,idvar = idvar,timevar = timevar,varying = varying,:
multiple rows match for Time.point=4: first taken
2: In reshapeWide(data,:
multiple rows match for Time.point=2: first taken
3: In reshapeWide(data,:
multiple rows match for Time.point=6: first taken
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)