On Tue, Mar 18, 2014 at 12:43 PM, Dustin Fife <fife.dus...@gmail.com> wrote:

> 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=".")
>
>
Backreferences

cat(
  gsub("(([[:alnum:]]+\\.){3})([[:alnum:]]+)\\.",
             "\\1\\2\n",
              fake
          )
)

That is, match three word/period sequences, match a word, match a period,
and output the first two things.

  -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

        [[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