-1
scorekm<-function(km, x,...)
{
    args<-list(x,...)
    m=data.frame(args)
}

I want to write a function in R, for example, when my input is scorekm(km, c(2,3,4), c(3,4,5)) The output should be

2 3 4
3 4 5

I know the function I put here is wrong, what ought it to be? For example,inputscorekm(km, c(2,3,4), c(3,4,5),c(4,5,6)),the out put should be

     [,1] [,2] [,3]
[1,]  2    3    4
[2,]  3    4    5
[3,]  4    5    6

But the number of parameters xin the function is uncertain.

Will Wang
  • 93
  • 1
  • 3
  • 10
  • Please provide a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – Henrik Oct 28 '13 at 14:29
  • the question is unclear. what is the desired output? or if I guess you want to manage missing arguments? – agstudy Oct 28 '13 at 14:33

2 Answers2

1

You actually, don't need to use the x arg, so you can leave it out

> scorekm<-function(km, ...) {
     args<-list(...)
     sapply(args, rbind)
 }

> scorekm(km, c(2,3,4), c(3,4,5), c(4,5,6))

     [,1] [,2] [,3]
[1,]    2    3    4
[2,]    3    4    5
[3,]    4    5    6
Diego Jimeno
  • 222
  • 4
  • 15
0

If you return the transpose of m this comes your desired output pretty near.

scorekm<-function(km, x,...)
{
  args<-list(x,...)
  m=data.frame(args)
  t(m)
}

scorekm(km,c(2,3,4), c(3,4,5))
           [,1] [,2] [,3]
c.2..3..4.    2    3    4
c.3..4..5.    3    4    5
EDi
  • 12,840
  • 2
  • 46
  • 56