[R] apply with function

Jörg Reuter joerg at reuter.at
Thu Oct 20 23:20:47 CEST 2011


(Iske <- matrix(c(1, 1, 1, 2, 2, 2, 10, 1, 1, 5,
1,2,2,2,1,1,1,4,4,4,4,3,3,3,30,3,3,3,3,3,3,3,5,4,4,4,4,4,44,2,2,2,2,4,5,5,5,5,5,5,5,5,95,1,2),
ncol = 5))
numtochar <- function(Zahl){
text <- rawToChar(as.raw(Iske[1,]))}
(Iske.char[]<-apply(Iske,1,numtochar))

I have a little problem with the command apply(). I want use the
function numtochar for every row and the result should be a vector
with the chars for every row.
At the moment the function numtorow create a char with all items, but
separate not every row.
I think the function apply is the right way, bu I did not know how to
use it at this example. Attention: At the real data set every row have
a other length (!)



More information about the R-help mailing list