Hello,
I have a function P1(p,Q0) filling a matrix as I want :
P1<-function(p,Q0){
B=matrix(0,Q0+1,Q0+1)
for (i in 1:(Q0)){
B[i,i]=(1-p)*(1-p)+p*p
B[i,i+1]= p*(1-p)
B[i+1,i]=p*(1-p)
}
B[1,1]=1-p
B[1,2]=p
B[Q0+1,Q0]=p*(1-p)
B[Q0+1,Q0+1]=1-p*(1-p)
return(B) }
If I want specific values for p, and all the corresponding matrices, I enter
p=seq(0.1,0.9,0.1)
Q0=6
map(p,P1(p,Q0))
and I get the error "Error in B[i,i]=(1-p)(1-p)+pp :
number of items to replace is not a multiple of replacement length".
whereas I get no error when trying manually each value of p.
Can you help me on that ?
Thanks.