It is quite obvious why you get the error message; check your data:
Error in wynik[, i] - dodawanie(wzorzec, wzorzec1) :
number of items to replace is not a multiple of replacement length
No suitable frames for recover()
i
[1] 1
dodawanie(wzorzec, wzorzec1)
[1] 3 5 4 2 6 3
str(wynik)
num [1:10, 1:2] 0 0 0 0 0 0 0 0 0 0 ...
You are trying to put 6 items (return value) into 10 rows of the
matrix; you must have a bug in your program.
On Thu, Aug 13, 2009 at 5:15 PM, Grześgregori...@gmail.com wrote:
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.
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
__
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.