-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Jean V Adams
Sent: Thursday, November 08, 2012 3:52 PM
To: nicolapon
Cc: r-help at r-project.org
Subject: Re: [R] Beginner help about output in R
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 <niqo at 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
function.
Basically, I created 2 functions, value1 and value2, that calculate
values, and I would like to print those two values to an output
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
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
first try, etc. How can I proceed so that I will add a new line to
output at every step instead of deleting the previous line?
Thank you very much for your answers!
Nicolas