[R] generic pasting of strings

Robert Lischke robert.lischke at zmms.tu-berlin.de
Tue Oct 31 12:36:45 CET 2006


Hi there,

is there a way to make the following code generic, so that i can paste()
the columns in tmp1 depending on the dimensions given in embed()?

> tmp1 <- embed(as.vector(shrinkTable$AOIname), dimension = 2);
> tmp1
       [,1]   [,2]
 [1,] "AOI4" "AOI1"
 [2,] "AOI6" "AOI4"
 [3,] "AOI4" "AOI6"
> tmp2 <- paste(tmp1[, 2], tmp1[, 1], sep = ">");
> tmp2
 [1] "AOI1>AOI4" "AOI4>AOI6" "AOI6>AOI4"

for dimension = 3 this would look like this:

> tmp1 <- embed(as.vector(shrinkTable$AOIname), dimension = 3);
> tmp1
      [,1]   [,2]   [,3]
 [1,] "AOI6" "AOI4" "AOI1"
 [2,] "AOI4" "AOI6" "AOI4"
> tmp2 <- paste(tmp1[ ,3], tmp1[, 2], tmp1[, 1], sep = ">");
> tmp2
 [1] "AOI1>AOI4>AOI6" "AOI4>AOI6>AOI4"

Any ideas?

Thanks for your help,


Robert Lischke



More information about the R-help mailing list