Dear Arun, Thankyou very much for your reply. You always come up to save the day. So kind of you...!!! Eliza > Date: Thu, 12 Dec 2013 12:36:18 -0800 > From: smartpink...@yahoo.com > Subject: Re: [R] function inside a function > To: eliza_bo...@hotmail.com > > > > Hi Eliza, > > Actually, I used the modified function by Berend. > fun <- function(x, krow) { > f <- numeric(length(x)) > f[1] <- A[krow,1] + x[2]- 1/x[1] > f[2] <- A[krow,2] +x[2] - sin(x[1]) > f > } > > x.start <- c(1,1) > t(sapply(seq_len(nrow(A)),function(i) nleqslv(x.start,fun,krow=i)$x)) > [,1] [,2] > [1,] 1.052828 0.2725286 > [2,] 1.131672 0.4487542 > [3,] 1.109174 0.4534483 > [4,] 1.093078 0.4935468 > [5,] 1.098613 0.4420152 > [6,] 1.088997 0.4384237 > [7,] 1.005843 0.2912907 > > A.K. > > On Thursday, December 12, 2013 3:16 PM, eliza botto <eliza_bo...@hotmail.com> > wrote: > > Dear Arun, > Thankyou very much for your reply. > > I m getting the following error. > May be i m not running the full code. > > i used it in the following way. > > library(nleqslv) > > fun <- function(x) { > f <- numeric(length(x)) > f[1] <- A[,1]+x[2] - 1/x[1] > f[2] <- A[,2]+x[2] - > sin(x[1]) > f > } > x.start <- c(1,1) > t(sapply(seq_len(nrow(A)),function(i) nleqslv(x.start,fun,krow=i)$x)) > Kindly see, if you could help. > Eliza > > > Date: Thu, 12 Dec 2013 11:01:47 -0800 > > From: smartpink...@yahoo.com > > Subject: Re: [R] function inside a function > > To: r-help@r-project.org > > CC: b...@xs4all.nl; eliza_bo...@hotmail.com > > > > Hi, > > May be this helps: > > t(sapply(seq_len(nrow(A)),function(i) nleqslv(x.start,fun,krow=i)$x)) > > > > > > A.K. > > > > > > On Thursday, December 12, 2013 1:54 PM, eliza botto > > <eliza_bo...@hotmail.com> wrote: > > Dear Berend,Thankyou very much for your reply. I actually wanted to inserts > > each row value of A in f[1] anf f[2], with column 1 value in f[1] and > > column 2 values in f[2]. Once that been done, i should have in the end, 124 > > vaues of x[1] for column 1 and 124 for column 2.I hope i am clear this > > time.Thanks for your help.Eliza > > > > > Subject: Re: [R] function inside a function > > > From: b...@xs4all.nl > > > Date: Thu, 12 Dec 2013 19:35:58 +0100 > > > CC: r-help@r-project.org > > > To: eliza_bo...@hotmail.com > > > > > > > > > On 12-12-2013, at 17:10, eliza botto <eliza_bo...@hotmail.com> wrote: > > > > > > > Dear users of R, > > > > I am trying to inculcate a function inside a function. For that to be > > > > done, i copied following function from internet. > > > > > > > > library(nleqslv) fun <- function(x) { > > > >á á f <- numeric(length(x)) > > > >á á f[1] <-á A[,1]+x[2] - 1/x[1] > > > >á á f[2] <-á A[,2]+x[2] - sin(x[1]) > > > >á á f > > > > } > > > > x.start <- c(1,1) > > > > nleqslv(x.start,fun) > > > > I have a matrix "A" with dimension 124 rows and 2 columns. In f[1] > > > > line, in place of A[,1] i want to inculcate each value (each row) of > > > > column 1 of matrix A. while doing it, In f[2] line, in place of A[,2] i > > > > want to inculcate each value (each row) of column 2 of matrix A.á > > > > For suppose A has following rows > > > > 0.6772941á á á á á á á á á á á á á á á 0.5962983 > > > > 0.4348938á á á á á á á á á á á á á á á 0.4563702 > > > > 0.4481236á á á á á á á á á á á á á á á 0.4418828 > > > > 0.4213013á á á á á á á á á á á á á á á 0.3944993 > > > > 0.4682232á á á á á á á á á á á á á á á 0.4485623 > > > > 0.4798529á á á á á á á á á á á á á á á 0.4477387 > > > > 0.7029005á á á á á á á á á á á á á á á 0.5533228 > > > > While using 0.66772941 in f[1], use 0.5962983 in f[2]. > > > > How can i do this in R. > > > > Thanks in advance, > > > > > > > > > It is not clear what you actually want. > > > Maybe something like this > > > > > > library(nleqslv) > > > > > > A <- matrix(c(0.6772941,á 0.5962983, > > >á á á á á á á 0.4348938,á 0.4563702, > > >á á á á á á á 0.4481236,á 0.4418828, > > >á á á á á á á 0.4213013,á 0.3944993, > > >á á á á á á á 0.4682232,á 0.4485623, > > >á á á á á á á 0.4798529,á 0.4477387, > > >á á á á á á á 0.7029005,á 0.5533228), byrow=TRUE,ncol=2) > > > > > > fun <- function(x, krow) { > > >á á f <- numeric(length(x)) > > >á á f[1] <- A[krow,1] + x[2]- 1/x[1] > > >á á f[2] <- A[krow,2] +x[2] - sin(x[1]) > > >á á f > > > } > > > > > > x.start <- c(1,1) > > > nleqslv(x.start, fun, krow=1) > > > nleqslv(x.start, fun, krow=2) > > > > > > > > > > Eliza ááá ááá ááá á ááá ááá á > > > > ááá [[alternative HTML version deleted]] > > > > > > > > > > Please do not post in HTML. You should know by now. > > > > > > Berend > > > > > > > ______________________________________________ > > > > 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 > > > > and provide commented, minimal, self-contained, reproducible code. > > > > > ááá ááá ááá á ááá ááá á > > ááá [[alternative HTML version deleted]] > > > > > ______________________________________________ > > 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 > > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]]
______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.