I am trying to run an analysis by invoking R through the command line as follows:
R --no-save < SampleProgram.R > SampleProgram.opt
For example, consider the simple R program below:
mydata = read.csv("test.txt", header=T)
attach(mydata)
summary(Variable1)
q()
The output is displayed in SampleProgram.opt (only partially shown):
> mydata = read.csv("test.txt", header=T)
> attach(mydata)
> summary(Variable1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.00 1.00 2.00 2.47 3.00 4.00
> q()
This simple R program is going to be executed by a script that needs to use the summary statistics displayed for Variable1.
The question is this: Is there any way in R to capture the output of summary(Variable1) and write the results into an output file? In other words, I need R to run the summary statistics for Variable1, capture the "Min", "Median" and "Max" values and write those alone to an output text file. In this example, the output file should contain only one line with the values "1.00, 2.00, 4.00" (i.e. the "Min", "Median" and "Max" values).
The example above talks about the summary function. But, I need to do that with other commands as well (such as glm)
I am fairly new to R and was wondering if there was a way in R that I could do this?
Thanks for the help.