Re: [R] rlnorm behaviour

2016-06-14 Thread Thierry Onkelinx
You need to study my examples and the helpfile of ifelse more carefully. Then you'll understand why your code is wrong. ​ ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance

Re: [R] rlnorm behaviour

2016-06-14 Thread Ayyappa Chaturvedula
I am sorry, I missed that. I think I made it more appropriate and not using unnecessary simulated values. Thank you for your help. fulldata$Wt<-ifelse(fulldata$Sex==1,rlnorm(length(fulldata$Sex[fulldata$Sex==1]), meanlog = log(85.1), sdlog = sqrt(0.0329)),

Re: [R] rlnorm behaviour

2016-06-14 Thread Thierry Onkelinx
Please keep r-help in cc. Yes. Have a look at this example ifelse( sample(c(TRUE, FALSE), size = 0.5 * length(letters), replace = TRUE), letters, LETTERS ) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie &

Re: [R] rlnorm behaviour

2016-06-14 Thread Thierry Onkelinx
Dear Ayyappa, ifelse works on a vector. See the example below. ifelse( sample(c(TRUE, FALSE), size = length(letters), replace = TRUE), letters, LETTERS ) However, note that it will recycle short vectors when they are not of equal length. ifelse( sample(c(TRUE, FALSE), size = 2 *

[R] rlnorm behaviour

2016-06-14 Thread Ayyappa Chaturvedula
Dear Group, I am trying to simulate a dataset with 200 individuals with random assignment of Sex (1,0) and Weight from lognormal distribution specific to Sex. I am intrigued by the behavior of rlnorm function to impute a value of Weight from the specified distribution. Here is the code: