Skip to content

Help with Function!

2 messages · Lars Bishop, Paul Johnson

#
On Fri, Mar 13, 2009 at 6:28 PM, Lars Bishop <lars52r at gmail.com> wrote:
indic <- matrix(c(1,1,0,0,0,1,0,0,1,0), ncol=5)

X <- data.frame(x1=3,x2=3,x3=4,x4=5,x5=6)

### Give this function 2 vectors, an "indicator
### vector ind and a value vector Xin
myHomework <- function(ind, Xin){
  prod(Xin[ , which(ind==1)])
}

myHomework(indic[1,], X[1,])

myHomework(indic[2,], X[1,])

Seems to give the right answer.  Let me know if we get an A.

PJ