vendredi 6 avril 2018

Using ifelse to change column names in R

I want to create a function that cleans some messy dataframes, and I need to specify the names of the columns according to some inputs using ifelse.

  aporte_apv <- c("Fondo", "Serie", "Cantidad.de.Aportes")
  aporte_ffmm <- c("Rut.Cliente", "Cuenta", "Fecha")

colnames(base) <- ifelse(tolower(transaccion)=="apv", aporte_apv, 
                         ifelse(tolower(transaccion)=="ffmm", aporte_ffmm, stop("not valid inputs")))

Apparently ifelse can't handle vectors, how can I do this in an elegant way?

Aucun commentaire:

Enregistrer un commentaire