Reputation: 35
I am truly a beginner in r programming. And I am stuck with this problem. What I try to do is that if the ifelse true then create a vector including different value. Such as if my q.matri= c(1,0,0)
then I would like to get a vector something like that (0.2466072,0.7819847)
.But it gives me the only one value which is 0.2466072
. Is not it possible to do such things with ifelse function?
Thanks in advance!
a= function(q.matri){
pc <- runif(1, IQ - VAR, IQ + VAR)
p0 <- runif(1,0.20 - VAR , 0.20 + VAR)
p2 <-runif(1,0.25 - VAR , 0.25 + VAR)
p3 <-runif(1,0.30 - VAR , 0.30 + VAR)
ifelse (
(sum(q.matri)==1),
c(p0,pc),
ifelse (
(sum(q.matri)==2),
c(p0, rep(p2, 2), pc),
ifelse (
(sum(q.matri)==3),
c(p0, rep(p2, 3), rep(p3, 3), pc)
)))}
Upvotes: 0
Views: 25
Reputation: 127
Hi I used the code you posted to formulated the program in R
a= function(q.matri){
pc = 1
p0 = 2
p2 =3
p3 =4
if(sum(q.matri)==1){
return(c(p0,pc))
}else if(sum(q.matri)==2){
return(c(p0, rep(p2, 2), pc))
}else if(sum(q.matri)==3){
return(c(p0, rep(p2, 3), rep(p3, 3), pc))
}}
About the IQR and Var function you need to specify about what data you want to calculate it, this link IQR explain how to use the IQR function in R and this link Var explain how to use the VAR function.
Upvotes: 1