data.frame
の行を削除しようとしましたが、列posn
の値が別のdata.frame
で指定された範囲になく、data.table
の非等価結合機能があります。ここでdata.table非等結合に結合列を変更しないでおく方法は?
は私のデータがどのように見えるかです:ここでは
library(data.table)
df.cov <-
structure(list(posn = c(1, 2, 3, 165, 1000), att = c("a", "b",
"c", "d", "e")), .Names = c("posn", "att"), row.names = c(NA,
-5L), class = "data.frame")
df.exons <-
structure(list(start = c(2889, 2161, 277, 164, 1), end = c(3329,
2826, 662, 662, 168)), .Names = c("start", "end"), row.names = c(NA,
-5L), class = "data.frame")
setDT(df.cov)
setDT(df.exons)
df.cov
# posn att
# 1: 1 a
# 2: 2 b
# 3: 3 c
# 4: 165 d
# 5: 1000 e
df.exons # ranges of `posn` to include
# start end
# 1: 2889 3329
# 2: 2161 2826
# 3: 277 662
# 4: 164 662
# 5: 1 168
私が試したものです:
df.cov[df.exons, on = .(posn >= start, posn <= end), nomatch = 0]
# posn att posn.1
# 1: 164 d 662
# 2: 1 a 168
# 3: 1 b 168
# 4: 1 c 168
# 5: 1 d 168
あなたはdf.cov
でposn
列も変更されていることがわかります。私はdata.table
非エクイ参加して所望の出力を得ることができますどのように
# posn att
# 1: 165 d
# 2: 1 a
# 3: 2 b
# 4: 3 c
# 5 165 d
# the row order doesn't matter. I'll sort by posn latter.
# It is also fine if the duplicated rows are removed, otherwise I'll do this in next step.
:期待される結果は次のようになりますか?
'df.cov [df.cov [df.exons、(POSN> =開始、POSN <=終了)、NOMATCH = 0、= TRUE]] '私は、この種のサブセットhttps://github.com/Rdatatable/data.table/issues/2158のFRを提出しました。それにはまだ答えました)。 dupesを削除するには、サブセット化する前に 'which'ベクトルに' unique'を適用してください。 – Frank
私はもう少し前に少し質問をしました:['' x 'のジョインカラムとその非ジョインカラムをすべて選択するには 'j'を使用します(https://stackoverflow.com/questions/42329157/use-j- x-and-all-its-non-join-columnsの列を選択する) – Henrik
@Frank、ありがとう。 'df.cov [sort(unique = df.cov [df.exons、on =。(posn> = start、posn <= end)、nomatch = 0、= TRUE]は、 ))] '。私はあなたのFRを読んで、このような機能が実際にこのような多くの場合に役立つと思います。 – mt1022