안녕하세요,
아래와 같이 2개의 열이 있는 데이터 테이블이 있습니다.
group value
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">10</SPAN>
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">20</SPAN>
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">25</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">5</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">10</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">15</SPAN>
"그룹"으로 그룹화된 연속 행 간의 차이를 계산하는 새 열 "diff"를 만들고 싶습니다. 따라서 다음과 같이 됩니다.
group value diff
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">10</SPAN> . <SPAN class="hljs-comment"># because there is a no previous value</SPAN>
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">20</SPAN> <SPAN class="hljs-number">10</SPAN> <SPAN class="hljs-comment"># value[2] - value[1]</SPAN>
<SPAN class="hljs-number">1</SPAN> <SPAN class="hljs-number">25</SPAN> <SPAN class="hljs-number">5</SPAN> <SPAN class="hljs-comment"># value[3] value[2]</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">5</SPAN> . <SPAN class="hljs-comment"># because group is changed</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">10</SPAN> <SPAN class="hljs-number">5</SPAN> <SPAN class="hljs-comment"># value[5] - value[4]</SPAN>
<SPAN class="hljs-number">2</SPAN> <SPAN class="hljs-number">15</SPAN> <SPAN class="hljs-number">5</SPAN> <SPAN class="hljs-comment"># value[6] - value[5]</SPAN>
</CODE><CODE class="hljs language-r">
열 수식에 대한 jsl을 도와주실 수 있습니까?
감사합니다.
알리시아
예와 같이 테이블이 항상 그룹별로 정렬되는 경우 if 문을 사용하여 이 작업을 수행할 수 있습니다.
If( Lag( :group ) == :group,
:value - Lag( :value ),
.
)