Hello!
I am writting a function, which should recycle one of its arguments if
length of the argument is approprate i.e. something like
foo - function(x, a)
{
n - length(x)
if(length(a) n) { # recycle a
oldA - a
a - vector(length=n)
a[1:n] - oldA
}
## ...
return(a)
}
Try:
foo2 - function(x, a) cbind(x,a)[,2]
On 7/23/06, Gregor Gorjanc [EMAIL PROTECTED] wrote:
Hello!
I am writting a function, which should recycle one of its arguments if
length of the argument is approprate i.e. something like
foo - function(x, a)
{
n - length(x)
if(length(a) n) {
Hi,
Gabor Grothendieck wrote:
Try:
foo2 - function(x, a) cbind(x,a)[,2]
thank you for this. It does work to some extent, but not much better
than mine foo.
foo2(c(1, 2, 3), a=1)
[1] 1 1 1
18:14:08
R foo2(c(1, 2, 3), a=c(1,2,3,4))
[1] 1 2 3 4
Warning message:
number of rows of result
Here is another possibility:
rep(a, length = length(x))
On 7/23/06, Gregor Gorjanc [EMAIL PROTECTED] wrote:
Hi,
Gabor Grothendieck wrote:
Try:
foo2 - function(x, a) cbind(x,a)[,2]
thank you for this. It does work to some extent, but not much better
than mine foo.
foo2(c(1, 2, 3),