我需要根据每组第一行的值为每组分组创建新行。
我正在尝试使用do(add_row())创建新行,并使用top_n从每个组的第一行访问值。
<?xml version="1.0" encoding="UTF-8"?><!--This file was generated by the
ALFA Plugin for Eclipse from Axiomatics AB (http://www.axiomatics.com). --><!--Any modification to this file will
be lost upon recompilation of the source ALFA file -->
<xacml3:Policy
xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
PolicyId="http://axiomatics.com/alfa/identifier/com.axiomatics.denyIfSameContent"
RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
Version="1.0">
<xacml3:Description>Ths policy will checks the contents of the user
label and the the resource label.
It will deny access if there is at least one value in the user label
equal to at least
one value in the resource label.
</xacml3:Description>
<xacml3:PolicyDefaults>
<xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
</xacml3:XPathVersion>
</xacml3:PolicyDefaults>
<xacml3:Target />
<xacml3:Rule Effect="Deny"
RuleId="com.axiomatics.denyIfSameContent.denyIfSameContent">
<xacml3:Description>This rule will deny access is user.label contains
at least 1 value that is also present
in object.label
</xacml3:Description>
<xacml3:Target />
<xacml3:Condition>
<xacml3:Apply
FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
<xacml3:AttributeDesignator
AttributeId="com.axiomatics.user.label"
Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false" />
<xacml3:AttributeDesignator
AttributeId="com.axiomatics.object.label"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
DataType="http://www.w3.org/2001/XMLSchema#string"
MustBePresent="false" />
</xacml3:Apply>
</xacml3:Condition>
</xacml3:Rule>
</xacml3:Policy>
但是我收到以下错误消息。
df = tibble(ID = rep(1:2, each = 2), x = rep(1:2, each = 2), y = seq(1:4))
gb_df <- group_by(df, ID, x)
new_df <- gb_df %>% do(add_row(., ID = top_n(.,1, wt=y)[,"ID"], x = 0, y =
top_n(.,1, wt=y)[,"y"]-1, .before=0))
我想要以下输出。
Error: Columns `ID`, `y` must be 1d atomic vectors or lists