> -----Original Message----- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > Suppose I have a function that takes three numeric arguments x, y, and z, any > of which may be scalars or vectors. > Suppose further that the user takes one of the arguments, say y, as a vector > with the other two as scalars. > Is there an existing R function that will promote the other two arguments to > vectors of the same size?
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}} ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.