[R] Unexpected input in function
Sarah Goslee
sarah.goslee at gmail.com
Mon Mar 19 21:33:23 CET 2012
I think you'll need to provide a reproducible example, because your
code works for me:
> fsubt <- function(a) {
+ b <- 1:length(a)
+ b-a
+ }
>
>
> fsubt(1:5)
[1] 0 0 0 0 0
>
> fsubt(sample(1:10))
[1] -8 -6 1 1 -1 5 3 1 4 0
>
> fsubt(2)
[1] -1
On Mon, Mar 19, 2012 at 4:01 PM, Schryver, Jack C. <schryverjc at ornl.gov> wrote:
> Hi,
>
> Although the following statements work individually in R, they produce an error if placed inside a function as below:
>
> fsubt <- function(a) {
> b <- 1:length(a)
> b-a
> }
>
> The error message is:
>
> Error: unexpected input in:
> "b <- 1:length(a)
> b-"
>
> Any insight would be greatly appreciated.
>
> Thanks,
> Jack
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list