Hello, I want call my function (use my database) and write every result in matrix "wynik" but I always get an error: Error in wynik[, i] <- dodawanie(wzorzec, wzorzec1) : number of items to replace is not a multiple of replacement length
I'll be very happy if sb help me dodawanie<- function ( wzorzec, wzorzec1){ wynik1<-wzorzec + wzorzec1 wynik2<-wzorzec * wzorzec1 wynik <- c(wynik1,wynik2) return (wynik) } df=data.frame(a=c(1,2,3),b=c(9,9,9),c=c(4,3,2)) # This is my database ;) wynik=matrix(0,nrow=10,ncol=2) # and my loop for(i in 1:ncol(df)){ procent_graniczny <- 10 wzorzec=df[,i] wzorzec1=ifelse(df$a==3,1,ifelse(df$c==4,2,3)) wynik[,i] <- dodawanie ( wzorzec, wzorzec1) # <- Here is my problem !!! I want in "wynik" have got result from my function (one by one) } -- View this message in context: http://www.nabble.com/write-result-in-matrix-using-loop-tp24958820p24958820.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.