Are you saying that you want to ignore the additional suffixes, _FA, _XRF,
and _XR?  If so, you can do so like this,
     sapply(strsplit(DATA_names, "_"), function(x) paste(x[1:2],
collapse="_"))
If not, what do you want to happen with those suffixes?

Jean



On Tue, Jul 9, 2013 at 6:20 AM, Shane Carey <careys...@gmail.com> wrote:

> Hi,
>
> I have the following data as labels:
>
> DATA_names<-c("A_ugkg_FA","S_mgkg_XRF" ,"Cl_mgkg_XR")
>
> and I need to convert to
>
>
>              -1
> A (ug kg     )
>
>              -1
> S (mg kg    )
>
>               -1
> Cl (mg kg    )
>
>
> I used the following piece of code to convert the following labels in the
> past, but cant get it to work for the new labels:
>
> f <- function (name)
> {
>   # add other suffices and their corresponding plotmath expressions to the
> list
>   env <- list2env(list(mgkg = bquote(mg ~ kg^{-1}),
>                        ugkg = bquote(mu * g ~ kg^{-1})),
>                   parent = emptyenv())
>   pattern <- paste0("(", paste(objects(env), collapse="|"), ")")
>   bquoteExpr <- parse(text=gsub(pattern,
>                                 "~(.(\\1))",
>                                 name))[[1]]
>   # I use do.call() to work around the fact that bquote's first argument is
> not evaluated.
>   do.call(bquote, list(bquoteExpr, env))
> }
>
> The labels in the past were:
> DATA_names<-c("A_ugkg","S_mgkg" ,"Cl_mgkg")
>
> Thanks
>
> --
> Shane
>
>         [[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.
>

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