Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Using SQL like '%word%' in R

$
0
0

I want to find the word bank and banco in a specific variable. In SQL I would use:

WHERE Name in ('%banco%','%bank%')

This is my exact query:

transacciones_diarias%>%mutate(TIPO_CAMBIO_POOL = case_when(
                                                grepl( '*banco*|*bank*',NOM_CLIENTE) & SEGMENTO != 'Individual' ~ MONTO_TIPOCAMBIOCOL
                                                ))

It still doesnt work

Sample data:

structure(list(FECHA_TRANSACCION = structure(c(17905, 17912, 
17914, 17914, 17924, 17928), class = "Date"), COD_CLIENTE = c(100L, 
100L, 100L, 100L, 100L, 100L), NOM_CLIENTE = c("BANCO CENTRAL DE LA REPUBLICA DOMINICANA", 
"BANCO CENTRAL DE LA REPUBLICA DOMINICANA", "BANCO CENTRAL DE LA REPUBLICA DOMINICANA", 
"BANCO CENTRAL DE LA REPUBLICA DOMINICANA", "BANCO CENTRAL DE LA REPUBLICA DOMINICANA", 
"BANCO CENTRAL DE LA REPUBLICA DOMINICANA"), COD_TIPOMOV = c("COMPRA", 
"COMPRA", "VENTA", "VENTA", "COMPRA", "COMPRA"), COD_MONEDA_BASE = c(1L, 
1L, 1L, 1L, 1L, 1L), MONTO_TOTAL_MOV = c(100500000, 100560000, 
756750000, 756750000, 100629200, 50337500), COD_MONEDA_DESTINO = c(2L, 
2L, 2L, 2L, 2L, 2L), MONTO_MONEDA_DESTINO = c(2e+06, 2e+06, 1.5e+07, 
1.5e+07, 2e+06, 1e+06), MONTO_TIPOCAMBIOCOL = c(50.25, 50.28, 
50.45, 50.45, 50.3146, 50.3375), TIPO_CAMBIO_DESTINO = c(1, 1, 
1, 1, 1, 1), TIPO_CAMBIO_POOL = c(NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_, NA_real_), TIPO_CAMBIO_POSICION = c(50.5356, 
50.5036, 50.4874, 50.4735, 50.4519, 50.5608), TIPO_CAMBIO_SOBREV = c(0, 
0, 0, 0, 0, 0), SUCURSAL = c("SUCURSAL LOPE DE VEGA", "SUCURSAL LOPE DE VEGA", 
"SUCURSAL LOPE DE VEGA", "SUCURSAL LOPE DE VEGA", "SUCURSAL LOPE DE VEGA", 
"SUCURSAL LOPE DE VEGA"), SEGMENTO = c("Empresarial", "Empresarial", 
"Empresarial", "Empresarial", "Empresarial", "Empresarial"), 
    ZONA = c("Metropolitana", "Metropolitana", "Metropolitana", 
    "Metropolitana", "Metropolitana", "Metropolitana"), CODIGO_OFICIAL = c("GNUNE2", 
    "GNUNE2", "GNUNE2", "GNUNE2", "GNUNE2", "GNUNE2"), CODIGO_USUARIO = c("EMGOMEZ", 
    "EMGOMEZ", "CRIVAS", "IBETANCES", "CRIVAS", "CRIVAS")), row.names = c(NA, 
6L), class = "data.frame")

Viewing all articles
Browse latest Browse all 201945

Trending Articles