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.