[R] Use of paste with apply()

Kjetil Brinchmann halvorsen kjetil at redcotel.bo
Sun Nov 6 14:34:16 CET 2005


I was surprised by:

 > test <- matrix( as.character(1:4), 2)
 > test
      [,1] [,2]
[1,] "1"  "3"
[2,] "2"  "4"
 > apply(test, 1, paste, sep="+")
      [,1] [,2]
[1,] "1"  "2"
[2,] "3"  "4"
 > apply(test, 1, paste, sep="*")
      [,1] [,2]
[1,] "1"  "2"
[2,] "3"  "4"
 > te <- matrix(1:4, 2)
 > te
      [,1] [,2]
[1,]    1    3
[2,]    2    4
 > apply(te, 1, sum)
[1] 4 6

Why doesn't paste behave in apply as sum?

Kjetil


-- 

Checked by AVG Free Edition.




More information about the R-help mailing list