[R] match help
Dimitris Rizopoulos
Dimitris.Rizopoulos at med.kuleuven.be
Mon Sep 3 19:18:46 CEST 2007
try this:
x <- c(NA, NA, 1, NA, NA, NA, NA, 2, NA, NA)
na.ind <- is.na(x)
x[na.ind] <- rnorm(sum(na.ind))
x
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting dverzi at mail.sdsu.edu:
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list