My question is how can i i input column numbers in the vars()
fucntion. If i input column positions, it doesnt work. However, if i input column names it works. Specifically with this code:
productos_por_profundidad <- productos_por_profundidad%>%
group_by(CODIGO_CLIENTE)%>%
summarise_at(vars(3:ncol(productos_por_profundidad)),function(x) sum((x)))
It worked with names, but that is not efficient in the long time.
data sample
productos_por_profundidad <- structure(list(CODIGO_CLIENTE = c(12554L, 125713L, 125724L, 126095L,
12618L, 12618L), SIGNIFICADO_ESTADO = structure(c(3L, 3L, 3L,
3L, 3L, 3L), .Label = c("Abandonada CE", "Activa CE", "ACTIVO CD",
"ACTIVO LEA/FAC", "ANULADO CD", "ANULADO PR", "APROBADO PR",
"Bloqueada parcialmente CE", "Bloqueada totalmente CE", "CAMBIO DE TIPO TC/MC",
"Cancelada CE", "CANCELADA TC/MC", "CANCELADO PR", "CASTIGADO PR",
"COBRO JUDICIAL PR", "DESEMBOLSADO PR", "Embargada CE", "Inactiva CE",
"LEGAL TC/MC", "MORA TC/MC", "NORMAL TC/MC", "OTROS PR", "PAGADO CD",
"Pendiente de aprobar CE", "PERDIDA O ROBADA TC/MC", "RECHAZADO PR",
"REESTRUCTURADO PR", "REGISTRADO PR", "RETENIDO CD", "SIN USO (3 O MAS MESES) TC/MC",
"TARJETA NUEVA TC/MC", "TARJETAS VENCIDAS TC/MC", "Transferida al BC CE"
), class = "factor"), `Certificado en Dolares (US$)` = c(0, 0,
0, 0, 0, 1), `Certificado en Pesos (RD$)` = c(1, 1, 1, 1, 1,
0), `Cuentas Corrientes en Pesos (RD$)` = c(0, 0, 0, 0, 0, 0),
`Cuentas de Ahorro en Dólares (USD$)` = c(0, 0, 0, 0, 0,
0), `Cuentas de Ahorro en Euros (EUR$)` = c(0, 0, 0, 0, 0,
0), `Cuentas de Ahorro en Pesos (RD$)` = c(0, 0, 0, 0, 0,
0), Factoring = c(0, 0, 0, 0, 0, 0), Leasing = c(0, 0, 0,
0, 0, 0), `Linea de Credito` = c(0, 0, 0, 0, 0, 0), Multicredito = c(0,
0, 0, 0, 0, 0), `Nómina Electrónica` = c(0, 0, 0, 0, 0, 0
), `Prestamo Comercial` = c(0, 0, 0, 0, 0, 0), `Prestamo de Vehiculo` = c(0,
0, 0, 0, 0, 0), `Prestamo en Tienda` = c(0, 0, 0, 0, 0, 0
), `Prestamo Hipotecario` = c(0, 0, 0, 0, 0, 0), `Prestamo Personal` = c(0,
0, 0, 0, 0, 0), `Tarjeta de Credito` = c(0, 0, 0, 0, 0, 0
)), row.names = c(NA, 6L), class = "data.frame")