[R] match help

dverzi at mail.sdsu.edu dverzi at mail.sdsu.edu
Mon Sep 3 19:01:26 CEST 2007


In my code, I would like to replace entries in t with 
entries from a random normal distribution.  

n<-10
> nl<-round(1.5+rexp(1,rate=2)
rate=2))
> nl
[1] 2
> r<-1:n 
> s<-sort(sample(r,nl))
> t<-match(r,s)
> r
 [1]  1  2  3  4  5  6  7  8  9 10
> s
[1] 3 8
>t
 [1] NA NA  1 NA NA NA NA  2 NA NA

t.random<-function(x) {for(i in 1:n) ifelse(x[i]!=NA, x[i]<-rnorm(1), x[i]<-NA}

t.random(t)

t
 [1] NA NA  1 NA NA NA NA  2 NA NA



Thank you for your time, 


Diana Verzi
Associate Professor of Mathematics



More information about the R-help mailing list