Consider using the indices instead of the matrices themselves.  You can pass
a list of indices and then reference the two matrices any way you want to
compute the return value.

On Fri, Mar 12, 2010 at 6:49 AM, Michal Szewczyk <miszewczyk@tlen.pl> wrote:

>
> Hello,
>
> I am struggling to overcome following problem:
>
> I have matrix Vf and matrix V, which both have 3 columns and I want to
> create a spline function basing on coordinates from this matrices (more
> precisely coordinates of function nr 1: x are taken from Vf[,1] and y are
> taken from V[,1] respectively), because function apply() base on 1 argument
> I made it in this way:
>
> Vspline<-matrix(0,nrow=2*n,ncol=K)
> Vspline<-rbind(Vf[,1:3],V[,1:3])
>
> where n=5000 and it is number of rows in V and Vf matrices
> and then:
>
> FV<-apply(Vspline,2, function(z)
> splinefun(Vspline[1:n,z],Vspline[(n+1):(2*n),z], method="mono",ties=mean))
>
> The problems is, that when I am running it, following error occurs:
>
> Error in xy.coords(x, y) : only 0's may be mixed with negative subscripts
>
> I was trying to run function apply replacing z with particular values, and
> it worked:
>
> FV<-apply(Vspline,2, function(z)
> splinefun(Vspline[1:n,1],Vspline[(n+1):(2*n),1], method="mono",ties=mean))
> FV<-apply(Vspline,2, function(z)
> splinefun(Vspline[1:n,2],Vspline[(n+1):(2*n),2], method="mono",ties=mean))
> FV<-apply(Vspline,2, function(z)
> splinefun(Vspline[1:n,3],Vspline[(n+1):(2*n),3], method="mono",ties=mean))
>
> However it does not solve the problem, because I am not obtaining objects
> FV[[1]], FV[[2]] and FV[[3]]. Object FV[[1]] is overwritten.
>
> My questions are:
> Why I am obtaining such an error?
> Is there any function that works like apply, but enables me to use two
> matrices as input data?
>
> Thanks in advance for any help.
>
> Greetings, Michal
>
> --
> View this message in context:
> http://n4.nabble.com/Usage-of-apply-function-with-two-matrices-tp1590442p1590442.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

