In order to use something like
temp<-generate.index(10)
your function should return something.
See ?return for more information, especially this
     If the end of a function is reached without calling 'return', the
     value of the last evaluated expression is returned.

The following code might be what you want.  (P.S Simple replacing cat 
with return will not work because return requires expression as "argument")

HTH

generate.index<-function(n.item){
  res<-""
  for (i in 1:n.item)
    {
      for (j in ((i+1):n.item))
        {
         
          
res<-paste(res,"i",formatC(i,digits=2,flag="0"),".",formatC(j,digits=2,flag="0"),"\n",sep="")
         
        }
     
    }
  return(res)
}




Dominik Heier wrote:

>Am Samstag, den 04.02.2006, 17:46 -0600 schrieb Taka Matzmoto:
>  
>
>>Hi R users
>>
>>I wrote a function that generates some character strings.
>>
>>generate.index<-function(n.item){
>>for (i in 1:n.item)
>>    {
>>        for (j in ((i+1):n.item))
>>            {
>>                
>>cat("i",formatC(i,digits=2,flag="0"),".",formatC(j,digits=2,flag="0"),"\n",sep="")
>>    
>>
>   ^
>replace "cat" with "return"
>  
>
>>            }
>>
>>    }
>>                                }
>>
>>I like to save what appears on the screen when I run using 
>>generate.index(10) as a character vector
>>
>>I used
>>temp <- generate.index(10)
>>
>>but it didn't work.
>>
>>Could you provide some advice on this issue?
>>
>>Thanks in advance
>>
>>TM
>>
>>______________________________________________
>>R-help@stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>    
>>
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>


-- 
Ferdinand Alimadhi
Programmer / Analyst
Harvard University
The Institute for Quantitative Social Science
(617) 496-0187
falimadhi@iq.harvard.edu
www.iq.harvard.edu


	[[alternative HTML version deleted]]


