我有以下矢量:
private static final ImmutableSet<String> OPTIONAL_CLASSES =
ImmutableSet.of(com.google.common.base.Optional.class.getName(), "java.util.Optional");
private static final Set<Kind> COMPARISON_OPERATORS =
EnumSet.of(Kind.EQUAL_TO, Kind.NOT_EQUAL_TO);
private static boolean isNull(ExpressionTree tree) {
return tree.getKind() == Kind.NULL_LITERAL;
}
private static boolean isOptional(ExpressionTree tree, VisitorState state) {
Type type = ASTHelpers.getType(tree);
for (String className : OPTIONAL_CLASSES) {
if (ASTHelpers.isSameType(type, state.getTypeFromString(className), state)) {
return true;
}
}
return false;
}
private boolean isSuppressed(Tree tree, String suppression) {
SuppressWarnings annotation = ASTHelpers.getAnnotation(ASTHelpers.getSymbol(tree), SuppressWarnings.class);
return annotation != null && Arrays.stream(annotation.value()).anyMatch(suppression::equals);
}
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
if (!COMPARISON_OPERATORS.contains(tree.getKind())) {
return Description.NO_MATCH;
}
ExpressionTree leftOperand = tree.getLeftOperand();
ExpressionTree rightOperand = tree.getRightOperand();
if (isNull(leftOperand) && isOptional(rightOperand, state) ||
isNull(rightOperand) && isOptional(leftOperand, state)) {
return describeMatch(tree);
}
return Description.NO_MATCH;
}
它是一个水平向量。
我有一个矢量:
lev <- c("apple", "key lime", "boston creme", "blueberry", "cherry", "pumpkin", "strawberry")
现在我想重新排序味道的级别,以便它们按计数降序排列。
我做的是pies$flavor
[1] cherry cherry cherry cherry cherry
[6] cherry cherry cherry cherry cherry
[11] cherry cherry cherry key lime key lime
[16] key lime key lime key lime key lime key lime
[21] key lime key lime key lime key lime key lime
[26] key lime key lime key lime key lime boston creme
[31] boston creme boston creme boston creme boston creme boston creme
[36] boston creme boston creme boston creme boston creme boston creme
[41] boston creme boston creme boston creme boston creme strawberry
[46] strawberry strawberry strawberry strawberry strawberry
[51] strawberry strawberry strawberry strawberry strawberry
[56] blueberry blueberry blueberry blueberry blueberry
[61] blueberry blueberry blueberry blueberry blueberry
[66] blueberry blueberry blueberry blueberry apple
[71] apple apple apple apple apple
[76] apple apple apple apple apple
[81] apple apple apple apple apple
[86] apple pumpkin pumpkin pumpkin pumpkin
[91] pumpkin pumpkin pumpkin pumpkin pumpkin
[96] pumpkin pumpkin pumpkin
但实际输出是错误的:
lev[order(table(pies$flavor), decreasing = T)]
因为按计数的实际顺序:
lev[order(table(pies$flavor), decreasing = T)]
[1] "apple" "cherry" "boston creme" "key lime" "blueberry"
[6] "pumpkin" "strawberry"
我做错了什么?