[R] Splitting vector into individual elements
Spencer Graves
spencer.graves at pdf.com
Wed Sep 15 22:35:24 CEST 2004
Have you considered "do.call":
> do.call("rgb", as.list((1:3)/10))
[1] "#1A334C"
same as:
> rgb(.1, .2, .3)
[1] "#1A334C"
Hope this helps. spencer graves
Paul Roebuck wrote:
>Is there a means to split a vector into its individual
>elements without going the brute-force route for arguments
>to a predefined function call?
>
> offred.rgb <- c(1, 0, 0) * 0.60;
>
> ## Brute force style
> offred.col <- rgb(offred.rgb[1],
> offred.rgb[2],
> offred.rgb[3],
> names = "offred")
> ## Desired style
> offred.col <- rgb(silver.bullet(offred.rgb),
> names = "offred")
>
>Neither of my attempts gets it right.
>
> silver.bullet.try1 <- function(x) {
> expr <- cat(x, sep = ",")
> return(parse(text = expr))
> }
>
> silver.bullet.try2 <- function(x) {
> expr <- expression(cat(x, sep = ","))
> return(eval(expr))
> }
>
>----------------------------------------------------------
>SIGSIG -- signature too long (core dumped)
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
--
Spencer Graves, PhD, Senior Development Engineer
O: (408)938-4420; mobile: (408)655-4567
More information about the R-help
mailing list