[R] avoid row/column indexing in capture.output

David Winsemius dwinsemius at comcast.net
Tue Jun 15 00:57:38 CEST 2010


On Jun 14, 2010, at 6:46 PM, David Winsemius wrote:

>
> On Jun 14, 2010, at 6:19 PM, Subodh Acharya wrote:
>
>> Hi everyone,
>> This might be a very petty thing but Its not working for me.
>> I want to export an output to a txt file but without indexing.
>
> Unfortunately we cannot see the structure of "output" but from the  
> result you are getting it looks like both "Time" and "output" might  
> be numeric vectors of the same length, although the [,1] access  
> looks wrong for a vector. Why don't you give us the result of  
> str(output)?
>
>> Here is what I  have tried to do
>>
>> outfile<- function(Time, var.names, output) {
>> var.names = c(names(para))
>> for(i in 1: ncol(output)){
>>  cat(length(var.names), '\n')
>>  cat("A", "S", "C", "I", '\n')
>>  cat("time =", "yes", '\n')
>>  cat("RUN", i, '\n')
>>  cat(length(Time), '\n')
>> #   print(cbind(Time, output[,i]))
>
> # Perhaps?
>
> cat( paste(Time, inp[ ,1], "\n"))  # since paste is "vectorized".

(I used a single column dataframe named inp to test what I thought was  
the structure of "output".)
>
> -- 
> David.
>
>> }
>> }
>> This works fine and
>> I get the output like as follows
>>
>> 4
>> A S  C I
>> time = yes
>> RUN 1
>> 111
>>      [,1]      [,2]
>> [1,] 0.00 1.7500000
>> [2,] 0.05 0.3983540
>> [3,] 0.10 0.6010150
>> [4,] 0.15 0.6759570
>> [5,] 0.20 0.7165215
>> [6,] 0.25 0.7423391
>> [7,] 0.30 0.7603594
>> [8,] 0.35 0.7737155
>> [9,] 0.40 0.7840432
>> [10,] 0.45 0.7922850
>> .
>> .
>> But I need need to have an output like this
>> 4
>> A S  C I
>> time = yes
>> RUN 1
>> 111
>> 0.00 1.7500000
>> 0.05 0.3983540
>> 0.10 0.6010150
>> ...
>>
>>
>> Any kind of help will be highly appreciated.
>>
>> Thank you in advance
>>
>> -- 
>> Acharya, Subodh
>>
>> 	[[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.
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list