[R] generic pasting of strings
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Oct 31 14:33:55 CET 2006
On 10/31/06, Robert Lischke <robert.lischke at zmms.tu-berlin.de> wrote:
> 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"
>
Try do.call like this:
do.call(paste, c(as.data.frame(tmp1), sep = ">"))
More information about the R-help
mailing list