bunny , lautloscrew.com
2006-Jul-20 19:42 UTC
[R] function names in a vector used by for (){} character problem ?
Hi there, i´m have vector of kernels. just like: kernels = c('gauss','epan','rectangular') i know there are density.default$kernels, but thats not my question here. my own kernel functions are running and working. my problem is the following is not working: dev.off() par(mfrow=c(3,3)) for(i in 1:length(bw)) { for(j in 1:length(kernels)) { par(mfg = c(i, j)) nawaline2(eruptions,waiting,kernels[j],bw[i],1000) # FYI: the following worked but ofcourse all rows were the same # nawaline2(eruptions,waiting,gauss,bw[i],1000) } } # here are the standard arguments for nawaline, kern exspects a function like gaussian, epan or rectangular. nawaline2(xi,yi,kern,h,N=1000) there´s bw vector also that works well. the problem seems that my kernels vector ist a vector of characters. I want to loop it using for ; but every time it runs through, there ´s an error, that kern can´t be found. i think it´s only beacause i don´t know how to get gauss instead of "gauss" and so on... has anybody an idea ? thanks so much in advance !! [[alternative HTML version deleted]]
Duncan Murdoch
2006-Jul-20 19:56 UTC
[R] function names in a vector used by for (){} character problem ?
On 7/20/2006 3:42 PM, bunny , lautloscrew.com wrote:> Hi there, > > i?m have vector of kernels. just like: > kernels = c('gauss','epan','rectangular') > > i know there are density.default$kernels, but thats not my question > here. my own kernel functions are running and working. > my problem is the following is not working: > > > dev.off() > par(mfrow=c(3,3)) > > > for(i in 1:length(bw)) > { > for(j in 1:length(kernels)) > { > par(mfg = c(i, j)) > nawaline2(eruptions,waiting,kernels[j],bw[i],1000) > # FYI: the following worked but ofcourse all rows were the same > # nawaline2(eruptions,waiting,gauss,bw[i],1000) > > } > } > > # here are the standard arguments for nawaline, kern exspects a > function like gaussian, epan or rectangular. > nawaline2(xi,yi,kern,h,N=1000) > > there?s bw vector also that works well. the problem seems that my > kernels vector ist a vector of characters. > I want to loop it using for ; but every time it runs through, there > ?s an error, that kern can?t be found. > i think it?s only beacause i don?t know how to get gauss instead of > "gauss" and so on...You could set up kernels as kernels <- list(gauss, epan, rectangular) and then pass kernels[[j]] instead of kernels[j]. Or your nawaline2 function could have something like if (is.character(kern)) kern <- get(kern, envir=parent.frame()) to go looking for the object with the name stored in kern. Duncan Murdoch> > has anybody an idea ? thanks so much in advance !! > > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch 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.
Douglas Bates
2006-Jul-20 19:59 UTC
[R] function names in a vector used by for (){} character problem ?
On 7/20/06, bunny , lautloscrew.com <bunny at lautloscrew.com> wrote:> Hi there, > > i?m have vector of kernels. just like: > kernels = c('gauss','epan','rectangular') > > i know there are density.default$kernels, but thats not my question > here. my own kernel functions are running and working. > my problem is the following is not working: > > > dev.off() > par(mfrow=c(3,3)) > > > for(i in 1:length(bw)) > { > for(j in 1:length(kernels)) > { > par(mfg = c(i, j)) > nawaline2(eruptions,waiting,kernels[j],bw[i],1000) > # FYI: the following worked but ofcourse all rows were the same > # nawaline2(eruptions,waiting,gauss,bw[i],1000) > > } > }> # here are the standard arguments for nawaline, kern exspects a > function like gaussian, epan or rectangular. > nawaline2(xi,yi,kern,h,N=1000)Use get(kernels[i]), not kernels[i]. This is, I believe, a FAQ.> there?s bw vector also that works well. the problem seems that my > kernels vector ist a vector of characters. > I want to loop it using for ; but every time it runs through, there > ?s an error, that kern can?t be found. > i think it?s only beacause i don?t know how to get gauss instead of > "gauss" and so on... > > has anybody an idea ? thanks so much in advance !! > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > > >
Reasonably Related Threads
- finite mixture model (2-component gaussian): plotting component gaussian components?
- Multivariate spline regression and predicted values
- glib2 head file error when build libvirt with wireshark support
- Probable bug in "An Introduction to R" (PR#10777)
- about different bandwidths in one graph