Re: [R] rearrange problem

2007-09-13 Thread jim holtman
Is this what you want: > n <- 10 > m <- 4 > x <- replicate(n, paste(letters[sample(1:26,m)], collapse='')) > x [1] "zmld" "tlme" "fonb" "aqwn" "onxl" "rpfx" "sler" "cvom" "ilme" "nbge" > x.sort <- sapply(x, function(.str){ + paste(sort(strsplit(.str, '')[[1]]), collapse='') + }) > x.sort zm

[R] rearrange problem

2007-09-13 Thread kevinchang
Hi All, I am trying to rearrange alphabetically each element in a character vector. ex: say the first element in the vector is "cba", and my goal is to turn it into "abc". The suggested function to use is sort(). But it turns out that sort doesn't work at the level of element. So I am wondering t