Skip to content

Add columns to data frame automatically

2 messages · Jesús Guillermo Andrade, jim holtman

#
Something like this might work where you are using 'lapply' to create
a list of values from the equivalent of the 'for' loop that you had.
You can then 'cbind' them to create a return matrix, or you can
convert it to a dataframe:

prep <- function()
{
# Clase[1]/Categoria[2]/Phi[3]/Rf[4]
  peso <- c(.0,.03,.3,.6)
# Extension del calculo
  result <- lapply(1:100, function(){

    # Calculos de todas las curvas
      # Variables (Valor Base)
      abase <- AlicuotaBruta
      clase <- llmcc$Clase
      as.numeric(peso)

      retValue <- (abase/llmcc$Clase)*peso[1]
      peso[1] <- peso[1]+(.01)
      cat("Modelos de Alicuotas:", i, peso[1], "\n")
      retValue
})
return (do.call(cbind, result))
}

On Fri, Feb 13, 2009 at 2:23 PM, Jes?s Guillermo Andrade
<jgandradev at mac.com> wrote: