關於<<運算符的管道問題/討論。<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />我已閱讀手冊(腳本指南,第11章),其中解釋了“嵌套和優先級”,並想知道其他人是否希望有一個更像管道操作員的選項(與%>%不同) magrittr R)中的運算符。因此,不必使用括號括起堆疊的消息
((object << message1)<< message2)<< message3
它會更自由,從左到右自然流動
object%>>%message1
%>>%message2
%>>%message3
Re:關於<<運算符的問題/討論。你可以做到這一點。 它可能不是未來維護的最佳方法;一個命名良好的變量可以澄清很多。
dt = open(“C:\ Program Files \ SAS \ JMPPRO \ 13 \ Samples \ Import Data \ bigclass_L.txt”)
<< selectwhere(13 <=:年齡<= 15)<< invertRowSelection << deleterows
<< newcolumn(“halfage”,式(年齡/ 2))
<< selectwhere(行()<= 10)<< invertRowSelection << deleterows;
您可以通過更改selectWhere條件使invertRowSelection消失。
這是有效的,因為我選擇了不創建新對象的消息(如<< subset)。 如果使用<< subset,則需要額外的parens以使後續消息轉到新對象。 使用子集可能比使用刪除更快。
六個月後,我寧願保持一些不那麼單一的東西:
allData = Open(“C:\ Program Files \ SAS \ JMPPRO \ 13 \ Samples \ Import Data \ bigclass_L.txt”);
ageSubset = allData << selectwhere(13 <=:age <= 15)<< subset(selected rows(1));
tenRows = ageSubset << selectwhere(Row()<= 10)<< subset(selected rows(1));
tenRows << New Column(“halfage”,formula(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)