Hi, if "a" is a constant, and "u" is a vector of random variables of arbitrary length, each of which is uniformly distributed between 0 and 1, then h(u) is a random sample of the function f.
So, if you adjust the code to the desired "a" and to the desired length "n," then you get a random sample of h(u) of length n. If that is not what you want to do, you need to state your question more precisely. Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Original Message----- From: khaz...@ceremade.dauphine.fr [mailto:khaz...@ceremade.dauphine.fr] Sent: Monday, December 21, 2009 3:33 PM To: Daniel Malter Subject: RE: [R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ? Hello Dear thank you for your answer, but I need to generate a sample from the function h(u) not compute the h(u). best khazaei > Hi, see the example below. There must be a way to do this with apply or > tapply, but it always returned an error "incorrect number of dimensions. > At > least the code below works > > n=100 > a=rnorm(n) > u=runif(n) > > f=function(x){min(x[,1],log(x[,2]))} > > x=data.frame(a,u) > > apply(x,1,f) #does not work > > #this works > y=NULL > for(i in 1:n) y[i]=f(x[i,]) > > HTH, > Daniel > > ------------------------- > cuncta stricte discussurus > ------------------------- > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On > Behalf Of khaz...@ceremade.dauphine.fr > Sent: Monday, December 21, 2009 5:17 AM > To: r-help@r-project.org > Subject: [R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ? > > Hello, > > How can generate a sample from h(u)=min{a,log(u)} for 0<u<1 in R,please? > > thank you > khazaei > > ______________________________________________ > 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. > > ______________________________________________ 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.