# Re: [R] Help on calculating a variable using random numbers

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Mon, 11 Apr 2011 14:09:01 -0700

Hi:

Try

simtest <- transform(simtest,

growth = rnorm(1000, m = ifelse(treat == 0, 0.1, 0.5), s = 0.03))

HTH,
Dennis

On Mon, Apr 11, 2011 at 1:16 PM, Shane Phillips <SPhillips_at_lexington1.net>wrote:

> I'm new to R, but I'm trying to write a program for a dissertation that
> generates a dataset as follows...
>
> subject=1:1000
> treat=rbinom(1*1000,1,.13)
> gender=rbinom(1*1000,1,.5)
> eth=runif(1*1000, min=1, max=4)
> cogat=rnorm(1*1000, 100, 16)
> map=rnorm(1*1000, 200, 9)
>
> simtest=data.frame (subject=subject, treat=treat, gender=gender,
> eth=round(eth,digits=0),
> cogat=round(cogat,digits=0),map=round(map,digits=0))
> simtest
>
> I need to add a variable named "growth". If the "treat" variable for an
> observation is 0 then "growth" needs to be a randomly generated a number
> from a normal distribution with a mean of .1 and a sd of .03. If the
> "treat" variable is 1 then "growth" needs to be a randomly generated a
> number from a normal distribution with a mean of .5 and a sd of .03.
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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. Received on Mon 11 Apr 2011 - 21:13:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Apr 2011 - 23:20:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.