Re: [R] saving a character vector

From: jim holtman <jholtman_at_gmail.com>
Date: Sun 05 Feb 2006 - 11:13:55 EST

Is this what you want? It returns a character vector with the values:

> generate.index<-function(n.item){

+ .return <- character()  # initialize vector
+ for (i in 1:n.item)
+    {
+        for (j in ((i+1):n.item))
+            {
+ # concatenate the results
+ .return <- c(.return,

paste("i",formatC(i,digits=2,flag="0"),".",formatC(j,digits=2,flag="0"),sep=""))
+
+            }
+
+    }
+    .return
+  }
>

>
> generate.index(10)
 [1] "i001.002" "i001.003" "i001.004" "i001.005" "i001.006" "i001.007"
 [7] "i001.008" "i001.009" "i001.010" "i002.003" "i002.004" "i002.005"
[13] "i002.006" "i002.007" "i002.008" "i002.009" "i002.010" "i003.004"
[19] "i003.005" "i003.006" "i003.007" "i003.008" "i003.009" "i003.010"
[25] "i004.005" "i004.006" "i004.007" "i004.008" "i004.009" "i004.010"
[31] "i005.006" "i005.007" "i005.008" "i005.009" "i005.010" "i006.007"
[37] "i006.008" "i006.009" "i006.010" "i007.008" "i007.009" "i007.010"
[43] "i008.009" "i008.010" "i009.010" "i010.011" "i010.010"
>

On 2/4/06, Taka Matzmoto <sell_mirage_ne@hotmail.com> wrote:

>

> 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="")
>

> }
>
> }
> }
>

> 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
>
--
Jim Holtman
Cincinnati, OH
+1 513 247 0281

What the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
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
Received on Sun Feb 05 11:28:23 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:23 EST