8

I am praticing R codes. When I type

sim.clt <- function (m=100,n=10,p=0.25)
{ z = rbinom(m,n,p)
  x = (z-n*p)/sqrt(n*p*(1-p))
  hist(x,prob=T,breaks=20,main=paste("n =",n,”p =”,p))
  curve(dnorm(x),add=T)
}

It gives me errors:

Error: unexpected input in:

    "  x = (z-n*p)/sqrt(n*p*(1-p))
      hist(x,prob=T,breaks=20,main=paste("n =",n,?
    >   curve(dnorm(x),add=T)
    > }
    Error: unexpected '}' in "}"
    > 

How to I fix the error? Thank you

zaq0718
  • 83
  • 1
  • 1
  • 3

1 Answers1

16

It seems you using unicode characters in your code: ”p =”,p).

Replace

hist(x,prob=T,breaks=20,main=paste("n =",n,”p =”,p))

by

hist(x,prob=T,breaks=20,main=paste("n =",n, "p =",p))
sgibb
  • 25,396
  • 3
  • 68
  • 74
  • Yes, you are right. I used unicode characters, and I replaced it. Apparently, it works. Thank you:) – zaq0718 Apr 28 '14 at 04:03
  • @zaq0718: Could you please accept the answer (hit the checkmark) if it solves your problem. – sgibb Apr 28 '14 at 09:32