Thank you all for your helpful comments! I solved my problem by creating an empty matrix before the loop and adjusting the loop itself, this is the code:
size <- dim(input) out <- matrix('',nrow =size[1], ncol = 9) for (i in 1:nrow(input)) { out[i,1:3] <- unlist(MyFunction(input[i,1],input[i,2], input[i,3]) out[i,4:6] <- unlist(MyFunction(input[i,5],input[i,7], input[i,6]) out[i,7:9] <- unlist(MyFunction(input[i,8],input[i,10], input[i,9]) } It's probably not the most efficient way of doing it but it gives me the desired output matrix... Thanks for pointing me to this pdf R inferno pdf, I had an old version of it.. I'm, starting to use R again after long time and this is a very useful guide! All the best Ale -- View this message in context: http://r.789695.n4.nabble.com/beginner-s-loop-issue-tp4469514p4471352.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.