I tried your proposition Sarah (I was answering to Berend when you posted your answer). Well it seems to work! I just had to add afterwords a line to have my NAs again. I converted values = 0 by NA (numeric() in the function did the contrary for the calculation):
mydata[mydata==0] <- NA At first it was working for such kind of data: NAs just in the middle of my data test <- data.frame(c(1,2,3,4,NA,NA,7,8,9,10),c(11,12,NA,14,15,16,17,NA,19,20)) colnames(test)<- c("data1","data2") but not for data with NAs at the beginning, in the middle and at the end: test2 <- data.frame(c(NA,2,3,4,NA,NA,NA,NA,NA,NA),c(NA,12,13,NA,15,16,17,NA,NA,NA)) colnames(test2)<- c("data3","data4") But thanks to your proposition, it seems to work in both cases now! Thanks a lot sarah! -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964p4623584.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.