什么是-c和nrow在这个函数中做什么?

时间:2017-07-25 14:22:37

标签: r

此功能中-cnrow的目的是什么?

bdf <- by(bdf, bdf$Serial_number, function(SN, k) {
                     SN[-c(1:k, (nrow(SN)-k+1):nrow(SN)),]
                     }, k = 10)

by()将数据帧bdf除以第二个参数Serial_number,apply将函数函数(SN,k)拆分为第三个参数。我不明白这个功能的主体。

1 个答案:

答案 0 :(得分:5)

LinkedList创建一个向量。 struct node { struct node *next; int score; }; /* Assumes that head is not NULL */ void remove_lowest(struct node **head) { if (*head) { struct node *current = *head; struct node *prev = NULL; struct node *lowest = current; struct node *low_prev = NULL; int low_score = current->score; while (current) { if (current->score < low_score) { lowest = current; low_prev = prev; low_score = current->score; } prev = current; current = current->next; } if (low_prev == NULL) { // first node is lowest *head = (*head)->next; } else if (lowest->next == NULL) { // last node is lowest low_prev->next = NULL; } else { low_prev->next = lowest->next; } free(lowest); } } 使向量中的数字为负数。向量位于&#34;行&#34; c()的位置,因此省略了从1到-,从[到数据框末尾的行。因此,它会截断数据框的第一行k和最后nrow(SN) - k + 1行。