[R] how can generate h(u)=min{a,log(u)} for 0<u<1 in R ?

Daniel Malter daniel at umd.edu
Mon Dec 21 12:02:02 CET 2009


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-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of khazaei at ceremade.dauphine.fr
Sent: Monday, December 21, 2009 5:17 AM
To: r-help at 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 at 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.




More information about the R-help mailing list