【发布时间】:2019-07-13 21:25:35
【问题描述】:
我正在尝试融合两列并通过以下方式使用行名作为 id:
fst = fread("file.fst")
colnames(fst) = c("fst2", "snp", "chr", "pos", "fst")
d <- melt(fst[,c("fst","fst2")], id.vars="as.numeric(row.names(fst))")
但我收到了错误:
Error in melt.data.table(fst[, c("fst", "fst2")], id.vars = "as.numeric(row.names(fst))") :
One or more values in 'id.vars' is invalid.
数据看起来像
fst2 snp chr pos fst
1: 0.265838 CLIC6 1 25001 0.150339
2: 0.390470 RUNX1 1 115001 0.259316
3: 0.126332 SETD4 1 635001 0.128946
4: 0.236400 LOC100222525 1 645001 0.117627
5: 0.181189 DOPEY2 1 705001 0.190456
> class(fst)
[1] "data.table" "data.frame"
> typeof(fst)
[1] "list"
> str(fst)
Classes ‘data.table’ and 'data.frame': 10066 obs. of 5 variables:
$ fst2: num 0.266 0.39 0.126 0.236 0.181 ...
$ snp : chr "CLIC6" "RUNX1" "SETD4" "LOC100222525" ...
$ chr : int 1 1 1 1 1 1 1 1 1 1 ...
$ pos : int 25001 115001 635001 645001 705001 735001 745001 955001 985001 1105001 ...
$ fst : num 0.15 0.259 0.129 0.118 0.19 ...
- attr(*, ".internal.selfref")=<externalptr>
怎么了?
【问题讨论】:
-
作为一般建议,我发现
tidyr中的gather使用起来更容易然后融化。