我想你想做的是
library(dplyr)
df %>%
mutate(inds = c(0,diff(x)),inds = -inds * (inds < 0)) %>%
group_by(y) %>%
summarise(sum = sum(inds))
# y sum
# <fct> <dbl>
#1 A 2
#2 B 5
#3 C 3
数据
df <- structure(list(y = structure(c(1L,1L,2L,3L,3L),.Label = c("A","B","C"),class = "factor"),x = c(3L,5L,0L,0L)),row.names = c("1","2","3","4","5","6","7","8","9"),class = "data.frame")
,
在global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000
frontend ELB
bind *:80
mode http
http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"
stats uri /haproxy?stats
stats auth hapuser:hapuser
acl apicall path_beg -i /api/
use_backend apigateway if apicall
acl explorercall path_beg -i /explorer/
use_backend apigateway if explorercall
default_backend weburl
backend weburl
mode http
balance leastconn
compression algo gzip
compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json image/svg+xml
http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"
server weburl1 127.0.0.1:3000 check port 80 inter 10s rise 2 fall 2
backend apigateway
mode http
balance leastconn
compression algo gzip
compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json image/svg+xml
http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"
server apigateway1 127.0.0.1:6001 check port 80 inter 10s rise 2 fall 2
内使用sum
,而无需使用$
,并在%>%
中使用set.seed
,以确保可重复性。
sample
,
您可以先使用 Integer total = 1;
double porcion = 3.5; //every single pizza
double bebida = 2.0; //the drink
double totalAmount = (total * porcion) + bebida;
String totalAmount2 = String.valueOf(totalAmount);
// This method increases the amount of pizzas
botonmas.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
total++;
tv1.setText(total.toString());
dinero.setText(totalAmount2);
}
});
// This method decreases the amount of pizzas
botonmenos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(total > 1){
total--;
tv1.setText(total.toString());
dinero.setText(totalAmount2);
}
}
});
创建mutate
列,然后再使用inds
:
summarise
,
您也可以在基数R中执行此操作。
aggregate(. ~ y,transform(DF,ind=-c(0,diff(DF$x)) * (c(0,diff(DF$x)) < 0)),sum)
# y x ind
# 1 A 9 2
# 2 B 6 5
# 3 C 5 3
数据
DF <- structure(list(y = c("A","A","C",class = "data.frame")
本文链接:https://www.f2er.com/3146566.html