On May 19, 2010, at 7:47 PM, Wu Gong wrote:
I tried to use a separate function to make the code more
understandable. But
I failed. I don't know what's wrong with the code.
x <- as.matrix(x)
rearrange <- function(.row){
z <- do.call(rbind, strsplit(.row[-1], ''))
z.col <- t(apply(z, 2, paste, collapse=''))
cbind(.row[1], z.col)
}
t(apply(x, 1, rearrange(.row)))
Error in strsplit(.row[-1], "") : object '.row' not found
The error occurs because apply is sending a single row at a time, but
it is not named .row. Your code _does_ work, but only if you use it
thusly:
t(apply(x, 1, rearrange))
I don't know how to pass the value to the function.
You may not, ... but R knows how.
-----
A R learner.
--
--
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.