I've got a dataset with really long column names (e.g.,
CYJ.OSU.OAV.UJC.BUT.RDI). What I'd like to do is replace the fourth period
with a break ("\n") so that when it plots, it will not run off the page.
Here's what I've got so far:

#### create fake names function
fake.names = function(x){
    paste0(LETTERS[sample(1:26,3)], collapse="")
}
#### create the fake names
fake = paste0(unlist(lapply(1:6, fake.names)), collapse=".")

#### replace fourth period with \n
gsub("[[:alnum:]]\\.[[:alnum:]]+\\.[[:alnum:]]+\\.[[:alnum:]]+\\.",
"[[:alnum:]]\\.[[:alnum:]]+\\.[[:alnum:]]+\\.[[:alnum:]]+\n",fake)

which results in something like:

"TW[[:alnum:]].[[:alnum:]]+.[[:alnum:]]+.[[:alnum:]]+\nNQJ.VSI"

Any ideas on how to make it replace that?

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to