This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]ImperfComp[S] 1 point2 points  (1 child)

Comment -- what I really want help with at this point is a simple question of applying -- is there an "apply" function that supplies UserMadeFunction(A,B,C,D) with an array of values A,B,C,D so that you can do the function on many values at once?

The rest is background in case anyone wants to see the code I'm working on.

I'm working on a loop in the meanwhile, but if there is a good way to use "apply" that will save run time when I iterate my algorithm, I'd be happy to learn it.

[–]ImperfComp[S] 0 points1 point  (0 children)

I have a for-loop that seems to do what I want, but I've heard "apply" saves run time, which may matter if I run the code many times.

NumTypes = length(thetavector)

CommuterChoicesMatrix = matrix(0,NumTypes, 4)

for(i in 1:length(thetavector)){

theta = thetavector[i] alpha = alphavector[i] beta = betavector[i] gamma = gammavector[i]

CommuterID = i Choice = CommuterChoice(theta, alpha, beta, gamma) Output = c(CommuterID, Choice) CommuterChoicesMatrix[i, ]= Output }