<< 연산자에 대한 파이프 라인 질문 / 토론.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />나는 '중첩과 선행 (Nesting and Precedence)'에 대해 설명하고 다른 사람들이 파이프 라인 운영자처럼 행동 할 수있는 옵션을 갖고 싶은지 궁금한 매뉴얼 (Scripting Guide, Ch 11)을 읽었습니다 (%> % 마그리트 R의 연산자). 따라서 누적 된 메시지를 다음과 같이 괄호로 중첩하지 않아도됩니다.
((개체 << 메시지 1) << 메시지 2) << message3
더 읽기 쉽고 자연스럽게 왼쪽에서 오른쪽으로 흐를 것입니다.
개체 % >> % message1
% >> % message2
% >> % message3
Re : << 연산자에 관한 질문 / 토론.너는 이것을 할 수 있었다. 미래 유지 관리를위한 최선의 접근법이 아닐 수도 있습니다. 잘 명명 된 변수는 많은 것을 명확히 할 수 있습니다.
dt = open ( "C : ₩ Program Files ₩ SAS ₩ JMPPRO ₩ 13 ₩ Samples ₩ Import Data ₩ bigclass_L.txt")
<< selectwhere (13 <= : age <= 15) << invertRowSelection << deleterows
<< newcolumn ( "halfage", 수식 (age / 2))
<< selectwhere (row () <= 10) << invertRowSelection << deleterows;
selectWhere 조건을 변경하여 invertRowSelection을 제거 할 수 있습니다.
이 작업은 << 하위 집합과 같은 새 개체를 만들지 않는 메시지를 선택했기 때문에 가능합니다. << 하위 집합을 사용하는 경우 후속 메시지를 새 개체로 이동하려면 추가 괄호가 필요합니다. 부분 집합을 사용하면 삭제를 사용하는 것보다 빠를 수 있습니다.
6 개월 후, 나는 다소 덜 획일적 인 것을 유지하려고한다.
allData = Open ( "C : ₩ Program Files ₩ SAS ₩ JMPPRO ₩ 13 ₩ Samples ₩ Import Data ₩ bigclass_L.txt");
ageSubset = allData << selectwhere (13 <= : age <= 15) << 부분 집합 (선택된 행 (1));
tenRows = ageSubset << selectwhere (Row () <= 10) << 부분 집합 (선택된 행 (1));
tenRows << 새 열 ( "halfage", 수식 (age / 2));
닫기 (allData, nosave);
닫기 (ageSubset, nosave);
Re : << 연산자에 관한 질문 / 토론.동기를 부여하기 위해 ... 다른 사람들이 JSL에서이 R / magrittr 예제를 어떻게 설명하는지 궁금하다.
Four operations are performed to arrive at the desired data set, and they are written in a natural order: the same as the order of execution. Also, no temporary variables are needed. If yet another operation is required, it is straight-forward to add to the sequence of operations wherever it may be needed.
the_data <-
read.csv ( '/ path / to / data / file.csv') %> %
하위 집합 (variable_a> x) %> %
transform (variable_c = variable_a / variable_b) %> %
헤드 (100)