0

I'm BRAND NEW to all coding so "like you're explaining it to an 8 year old" answers please!

I have created a function that trails off the right side of my typing area (top left box in RStudio).

MySamplingDistribution <- function(myVector)

{
return(mean(replicate(100, mean(sample(myVector, size=20, replace=TRUE)), simplify=TRUE)))
}

It runs fine in that format, but when I try to break it up on to 2 lines, like my book tells me:

MySamplingDistribution <- function(myVector)

{
return(mean(replicate(100, mean(sample(myVector,+
size=20, replace=TRUE)), simplify=TRUE)))
}

I get this error:

Error: unexpected '}' in "}"

I'm sure it's just some issue with spaces or tabs or something but I've attempted enough combinations and browsed enough forums to be asking here. I've just installed and am using RStudio, if that makes a difference.

THX!

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
user3316848
  • 1
  • 1
  • 1
  • 8
    Remove the `+`. That's something the interpreter adds to denote code you have tried to run which is syntactically incomplete. – Simon O'Hanlon Feb 16 '14 at 21:22
  • 1
    You should use an IDE (try Rstudio, ESS, Eclipse+StatET, in no particular order). It will indent code for you. – Roman Luštrik Feb 16 '14 at 21:44
  • You can add an arbitrary amount of white space (or line breaks) after any `,`, `(`, `[`, `{`, amongst other characters. You can only add a line break after an unquoted `+` if the `+` is appropriate in the context (e.g. if you are performing an addition) – jbaums Feb 16 '14 at 21:54
  • Possible duplicate of [Split code over multiple lines in an R script](https://stackoverflow.com/questions/6329962/split-code-over-multiple-lines-in-an-r-script) – divibisan Mar 09 '18 at 19:15

0 Answers0