Function always returns numeric(0)
r
Solution
As pointed out by joran, this is because vectors in R are 1-indexed.
Thanks, joran! (And doh!)
Problem
I'm quite new to R, so I apologize if this is a trivially easy question. I tried Googling, but could not find examples that seemed completely relevant (most examples only have 1 function argument). I have a simple function representing a basic linear model in 2 dimensions: ``` y <- function(x, w) { temp <- w[0] + x*w[1] return(temp) } ``` When I use it the way I expect, I get: ``` > y(1,c(-0.3,0.5)) numeric(0) ``` When I try an incorrect input, same thing! ``` > y(1,2) numeric(0) ``` Ultimately, my goal is to be able to have a vector, X, that can be passed in as the argument. For example: ``` > y(c(1,2,3,4),c(1,2)) ```