An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090213/c254ebfe/attachment-0001.pl>
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:
Hello fellows: I've een trying to set up a function that performs 100
loops producing the coresponding 100 series. I want to save all those
datasets in a dataframe, so I wrote this...
prep <- function()
# Clase[1]/Categoria[2]/Phi[3]/Rf[4]
peso <- c(.0,.03,.3,.6)
# Extension del calculo
for (i in 1:100)
{
# Calculos de todas las curvas
# Variables (Valor Base)
abase <- AlicuotaBruta
clase <- llmcc$Clase
as.numeric(peso)
df.clases <- data.frame()
df.clases[,i] <- (abase/llmcc$Clase)*peso[1]
peso[1] <- peso[1]+(.01)
cat("Modelos de Alicuotas:", i, peso[1], "\n")
}
return (df.clases)
Problem is: the function does not work, and I just cant seem to
understand how to save the results for every iteration where the value
of i and peso[1] changes.
Any ideas?
H?gale un favor a alguien y le tendr? que hacer muchos mas. Ley de
Pinto.
------------------------------
Jes?s Guillermo Andrade (Abg.)
Gerente de Litigios y Corporativo. EDM. AC. API.
Andrade & Moreno S.C. (http://amlegal.wordpress.com/)
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?