Displaying 20 results from an estimated 400 matches similar to: "integrate"
2007 May 02
2
how to reproduce the same sampled units?
Hi all,
Is it possible to generate the same sample number of times in R? In
SAS, using the option "seed" it is possible to reproduce exactly the
same sample. Is there any such feature in R which I can use?
For further clarity,
for (i in 1:2)
{
samp = sample(1:1000,100,replace = FALSE)
print(samp)
}
For the above simulation, is it possible to generate the same sampled
units
2007 Oct 24
1
plot within a loop
Hi ,
I'm having problem with the following plot. Basically I have to do
51(length of d, see below) plots. I want 6 plots (say) in a page and
rests are in different pages. win.graph() starts a plot in new page. But
I'm not being able to combine par(mfrow = c(3,2)) and win.graph() within
a loop.
> d
[1] 14.108 13.883 11.022 13.426 2.341 9.010 12.868 15.603 30.810
3.931 11.825
2006 Apr 04
2
Return function from function with minimal environment
Hi,
this relates to the question "How to set a former environment?" asked
yesterday. What is the best way to to return a function with a
minimal environment from a function? Here is a dummy example:
foo <- function(huge) {
scale <- mean(huge)
function(x) { scale * x }
}
fcn <- foo(1:10e5)
The problem with this approach is that the environment of 'fcn' does
not
2010 Jun 09
2
OOP and passing by value
Greetings,
I love the R system and am sincerely grateful for the great effort the
product and contributors
are delivering.
My question is as follows:
I am trying to use S4 style classes but cannot write functions that modify
an object
because paramter passing is by value.
For example I want to do this:
setGeneric("setData", function(this,fcn,k){ standardGeneric("setData")
2016 Mar 13
1
formals(x)<- drops attributes including class
Just checking in to see whether it is intended or not that assigning
new formals to a function/closure causes any attributes to be dropped:
EXAMPLE:
> fcn <- structure(function() {}, foo="foo", class=c("foo"))
> str(fcn)
function ()
- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 18 1 30 18 30 1 1
.. ..- attr(*, "srcfile")=Classes
2011 Mar 15
1
Problem with nls.lm function of minpack.lm package.
Dear R useRs,
I have a problem with nls.lm function of minpackl.lm package.
I need to fit the Van Genuchten Model to a set of data of Theta and hydraulic conductivity with nls.lm function of minpack.lm package.
For the first fit, the parameter estimates keep changing even after 1000 iterations (Th)
and
I have a following error message for fit of hydraulic conductivity (k);
Reason for
2003 Oct 30
2
'nls' and its arguments
Dear R experts!
I'd to fit data by 'nls' with me-supplied function 'fcn'.
1) I'd like 'fcn' to accept arbitrary arguments, i.e. I defined it
as f(...) {<body>}. (Ok, that's not actually impotant).
2) Second, I would NOT like to supply every parameter in the formula.
To illustrate this, let's look at the last example of 'nls' help
2010 May 14
1
debugging substitute function in R 2.11
Dear list,
A while ago I found in the web a function (sadly I can't credit the
author as I don't remember where I picked it up from) whose output is
a dataframe that lists for every object in the global environment its
class, mode, dim & length (where applicable). It is meant to be an
upgrade to the ls () function with a far more informative and detailed
output and it quickly became
2024 Feb 06
1
[EXTERNAL] Re: NOTE: multiple local function definitions for ?fun? with different formal arguments
Here's a dummy example that I think illustrates the problem:
toto <- function() {
if (runif(1) < 0.5)
function(a) a
else
function(a,b) a+b
}
> fcn <- toto()
> fcn(1,2)
[1] 3
> fcn <- toto()
> fcn(1,2)
[1] 3
> fcn <- toto()
> fcn(1,2)
Error in fcn(1, 2) : unused argument (2)
How can you use the returned function, if you get different arguments?
2013 Feb 05
1
integrate: Don't do this?
When I run the following function
HQ2 <- function(n) {
nv <- 6 * sqrt(n)
fcn <- function(z) {
pchisq(z^2 / 36, n - 1) * dnorm(nv - z)
}
## I want the integral from 0 to infinity:
f.Inf <- integrate(fcn, 0, Inf)
## Doc: "Don't do this":
f.100 <- integrate(fcn, 0, 100)
cbind(f.Inf, f.100)
}
I get, for n = 9 and
2008 Apr 22
4
how to convert non numeric data into numeric?
I am having the following error in my function
function(theta,reqdIRR)
{
theta1<-theta[1]
theta2<-theta[2]
n<-length(reqdIRR)
constant<- n*(theta1+theta2)
sum1<-lapply(reqdIRR*exp(theta1),FUN = sum)
sum2<-lapply(exp(theta2 - reqdIRR*exp(theta1)),FUN = sum)
sum = sum1 + sum2
log.fcn = constant - as.numeric(sum)
result = - log.fcn
return(result)
}
*error :
2007 Sep 29
2
Help with functions (iterations)
Hello:
I am a bit confused by this problem. Can anyone give me some advice on this I would greatly appreciate it. Thank you for all your help.
Need to create a for loop that saves the estimate of pi from each 0f 100 separate iterations and store it in a numeric vector (of length 100). The for loop should be placed in a function that allows the user to vary the sample size, the simulation size,
2002 Jan 23
1
Question about substitute (and eval, parse and deparse)
I would like to define a function at run-time, but I just can't make it
work (please don't question why I want to do this, because that would be
too much to explain). For example, I want to define the the following
function
foo <- function(x) {
cat("Function", "foo", "was called with argument", x, ".\n")
}
However, I would like to
2006 Apr 05
1
predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
Hi,
forget about the below details. It is not related to the fact that
the function is returned from a function. Sorry about that. I've
been troubleshooting soo much I've been shoting over the target. Here
is a much smaller reproducible example:
x <- 1:10
y <- 1:10 + rnorm(length(x))
sp <- smooth.spline(x=x, y=y)
ypred <- predict(sp$fit, x)
# [1] 2.325181 2.756166 ...
2011 Dec 14
1
uniroot function question
I have one equation, two unknowns, so I am trying to build the solution set
by running through possible values for one unknown, and then using uniroot
to solve for the accompanying second solution, then graphing the two
vectors.
p0 = .36
f = function(x) 0.29 * exp(5.66*(x - p0))
f.integral = integrate(f, p0, 1)
p1 = p0 + .01
i = 1
n = (1 - p0)/.01
p1.vector = rep(0,n)
p2.vector = rep(0,n)
for (i
2008 Jan 08
1
use "save.image" inside a function?
Hi, All
I'm trying to save the workspace as a Check Point for
possible future come back. The "save.image" function
works if the whole coding is in a main function:
rm(list=ls())
t = 1
t = t+1
print(paste("before",t))
# [1] "before 2"
save.image("tt.RData")
t = t+1
print(paste("after",t))
# [1] "after 3"
2013 Sep 30
1
how to interpose my own "[" function?
I want to create my own "[" function (for use on vectors, matrices,
arrays, etc.), which calls the stock R "[", does some additional work,
and then finally returns the modified result.
But, how do I properly call the stock R "[" function? It takes a
varying number of positional arguments, and its R-level closure is
just: .Primitive("[") It's
2005 Jun 10
1
Exiting R and package detachment?
Hi,
is there away to assure that a package is detached when R quits? I know
about .Last(), but that requires the user to setup that function. What
I am looking for is a way for the package to do this itself, without
asking the user to edit "their" .Last(). From ?setHook I know that:
"...when an R is finished, packages are not detached and namespaces
are not unloaded, so
2014 Dec 08
2
[LLVMdev] Virtual register problem in X86 backend
Hi,
I'm having trouble using virtual register in the X86 backend.
I implemented a new intrinsic and I use a custom inserter. The goal of
the intrinsic is to set the content of the stack to zero at the end of
each function.
Here is my code:
MachineBasicBlock *
X86TargetLowering::EmitBURNSTACKWithCustomInserter(
MachineInstr *MI,
MachineBasicBlock
2006 Jul 27
6
Any interest in "merge" and "by" implementations specifically for sorted data?
Hi Developers,
I am looking for another new project to help me get more up to speed
on R and to learn something outside of R internals. One recent R
issue I have run into is finding a fast implementations of the
equivalent to the following SAS code:
/* MDPC is an integer sort key made from two integer columns */
MDPC = (MD * 100000) + PCO;
/* sort the dataset by the key */
PROC SORT;