Skip to content
Prev 361108 / 398506 Next

promoting scalar arguments to vectors in a function

This depends on what you mean by 'promote' ...

If you want to do something like 'recycling', as is often done for plot colours, but need things the same length for subsetting etc, one crude but fairly straightforward way I will confess to using in a function is something like

L <- max( length(x), length(y), length(z) )
x <- rep(x, length.out=L) 
y <- rep(y, length.out=L) 
z <- rep(z, length.out=L)

If you wanted to zero-fill to the same length, or fill with NA, that'd be something else ...

S Ellison




*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
Message-ID: <1A8C1289955EF649A09086A153E2672403E14A8CD6@GBTEDVPEXCMB04.corp.lgc-group.com>
In-Reply-To: <OFBC2106C8.7A59FA6B-ON85257FBC.0056D26D-85257FBC.0057E1BA@ria.buffalo.edu>