求教一下,要将下列向量中的每一个数都通过自编函数计算结果,函数是一个分段计算的函数,有什么好的办法吗?能用循环不,怎么用呢?
g1<-c(0.17,0.26,0.09,0.41)
g2<-c(0.31,0.18,0.40,0.07,0.28)
g3<-c(0.32,0.14,0.18,0.26,0.62)
g4<-c(0.55,0.47,0.39,0.16)
fun<-function(x){
if(x==0){
result<-1
}
else if((x>0)&(x<=0.2)){
result<-0.5-0.5*sin(pi*(x-0.1)/0.2)
}
else{
result<-0
}
return( result)
}


雷达卡





京公网安备 11010802022788号







