I have a function that take a variable number of arguments, each of which
must be a vector.
Is there a way to "unbind" a matrix that would pass the columns as
vectors?
Myfunc<-function(...) {
[My code]
}
Myfunc(z[,1],z[,2]) works
but Myfunc(z[,1:2]) is passing a submatrix
Is there something like Myfunc(unbind(z[,1:2])) ??
--
View this message in context:
http://n4.nabble.com/unbind-matrix-tp1597887p1597887.html
Sent from the R help mailing list archive at Nabble.com.
?c On Mar 18, 2010, at 8:39 AM, ManInMoon wrote:> > I have a function that take a variable number of arguments, each of > which > must be a vector. > > Is there a way to "unbind" a matrix that would pass the columns as > vectors? > > Myfunc<-function(...) { > [My code] > } > > Myfunc(z[,1],z[,2]) works > > but Myfunc(z[,1:2]) is passing a submatrix > > Is there something like Myfunc(unbind(z[,1:2])) ?? > > > -- > View this message in context: http://n4.nabble.com/unbind-matrix-tp1597887p1597887.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD West Hartford, CT
I am trying to un-c... -- View this message in context: http://n4.nabble.com/unbind-matrix-tp1597887p1597987.html Sent from the R help mailing list archive at Nabble.com.
Did you try it? On Mar 18, 2010, at 10:03 AM, ManInMoon wrote:> > I am trying to un-c... > -- > View this message in context: http://n4.nabble.com/unbind-matrix-tp1597887p1597987.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > 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.David Winsemius, MD West Hartford, CT
I think I may have figured out what you _might_ have meant. An example would have speeded this process up considerably. Try: apply(mtx, 2, function) # perhaps within the MyFunc ... that you also did not provide. -- David. On Mar 18, 2010, at 10:03 AM, ManInMoon wrote:> > I am trying to un-c...-- David Winsemius, MD West Hartford, CT
Convert your matrix to a data frame and use do.call().
?do.call
do.call(Myfunc, data.frame(yourMatrix))
You need to do the data frame conversion because do.call wants the arguments
as a list and a data frame **is** a list (the columns are the list members)
with a dim attribute (+ others).
Bert Gunter
Genentech Nonclinical Biostatistics
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of ManInMoon
Sent: Thursday, March 18, 2010 5:39 AM
To: r-help at r-project.org
Subject: [R] "unbind" matrix?
I have a function that take a variable number of arguments, each of which
must be a vector.
Is there a way to "unbind" a matrix that would pass the columns as
vectors?
Myfunc<-function(...) {
[My code]
}
Myfunc(z[,1],z[,2]) works
but Myfunc(z[,1:2]) is passing a submatrix
Is there something like Myfunc(unbind(z[,1:2])) ??
--
View this message in context:
http://n4.nabble.com/unbind-matrix-tp1597887p1597887.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
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.