Dear All, I hope you don't mind helping me with this small issue. I haven't been using R in years and I'm trying to fill in a matrix with the output of a function (I'm probably using the Matlab logic here and it's not working). Here is my code:
for (i in 1:length(input)){ out[i,1:3] <- MyFunction(input[i,1],input[i,2], input[i,3]) out[i,4:6] <- MyFunction(input[i,5],input[i,7], input[i,6]) out[i,7:9] <- MyFunction(input[i,8],input[i,10], input[i,9]) } 'input' is a matrix > dim(input) [1] 46 10 and each raw corresponds to a different subject. The error I get here is /Error in out[i, 1:3] <- get.vaTer(input[i, 2], input[i, 4], input[i, 3], : object 'out' not found/ So I wonder, what's wrong in the assignment to the variable out? Should I define the variable before the loop? Thanks for your help Best Ale -- View this message in context: http://r.789695.n4.nabble.com/beginner-s-loop-issue-tp4469514p4469514.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.