[R] Splitting vector into individual elements

Liaw, Andy andy_liaw at merck.com
Wed Sep 15 23:46:56 CEST 2004


> From: Paul Roebuck
> 
> On Wed, 15 Sep 2004, Peter Dalgaard wrote:
> 
> > Paul Roebuck <roebuck at odin.mdacc.tmc.edu> writes:
> >
> > > 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")
> >
> > The closest is probably this:
> >
> > offred.col <- do.call("rgb", c(as.list(offred.rgb),
> >                                list(names="offred")))
> 
> Everyone offered 'do.call' as the solution. While that
> works, is it to say that there is no means of expanding
> the expression as an argument to the original function?

What would be the point?  That's what do.call() does for you internally.

Andy
 
> > (ever read/seen The Handmaid's Tale, btw?)
> >
> 
> Not yet. Though renaming my sample variable 'off.red.col'
> would avoid future confusion with oppressed handmaids.
> 
> ----------------------------------------------------------
> 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
> 
>




More information about the R-help mailing list