Error: Unexpected '}' in "}" in R [Duplicate]

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

3

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))
2
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest