关于<<运算符的管道问题/讨论。<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)