Nicolas,

Maybe something like this would work for you.  Put all of your x values in 
a list (or a vector, if your x values are scalars).  Use sapply to loop 
through all of your x values, applying the value1() and value2() 
functions, and saving the results in a data frame.  Then write the data 
frame to a file.

allofmyxs <- list(x1=48, x2=21, x3=1.9)
mydf <- as.data.frame(t(sapply(allofmyxs, function(x) c(value1(x), 
value2(x)))))
write.table(mydf, file=output.txt)

Jean



nicolapon <n...@msn.com> wrote on 11/08/2012 03:14:51 PM:
> 
> Dear R experts,
> 
> I am a beginner with R and I have a question regarding the output of a
> function.
> 
> Basically, I created 2 functions, value1 and value2, that calculate two
> values, and I would like to print those two values to an output 
datafile. I
> tryed the following function:
> 
> function (x) 
{write.table(data.frame(value1(x),value2(x)),file=output.txt)}
> 
> My problem is that I would like to calculate those values for different
> values of x and to get one line in the output file per value.
> When I use this function for the second time, it erases the value of the
> first try, etc. How can I proceed so that I will add a new line to the
> output at every step instead of deleting the previous line?
> 
> Thank you very much for your answers!
> 
> Nicolas

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to