不等式を満たす実際の値のエントリを含む列を含む、がありdata.table
ます。これらのエントリをたとえば10の間隔で「グループ化」したいと思います。具体的には、値0.1を割り当てたいすべての値に、値0.2などを割り当てたいすべての値にDT
C
0 < x <= 1
x
C
0 < x <=0.1
x
C
0.1 < x <=0.2
以下は私が書いた関数で、これを実行できると思いました(簡単ですが、私はRに比較的慣れていません!)。
r = function(x,N){
v = numeric(10)
for(i in 1:N)
v[i] = i/N*(x>(i-1)/N & x<=i/N)
v = v[v!=0]
return(v)
}
ここN
で、は必要な間隔の数です。ただし、コード:
DT = DT[,newC:=r(x=C,N=10)]
次のエラーが発生します。
Warning messages:
1: In v[i] = i/10 * (x > (i - 1)/10 & x <= i/10) :
number of items to replace is not a multiple of replacement length
2: In v[i] = i/10 * (x > (i - 1)/10 & x <= i/10) :
number of items to replace is not a multiple of replacement length
...
10: In v[i] = i/10 * (x > (i - 1)/10 & x <= i/10) :
number of items to replace is not a multiple of replacement length
どんな助けでも大歓迎です!乾杯