dimanche 31 janvier 2021

how to write conditions in R

I want to write a condition in R from : at first, I wrote this code for generating a random integer between 0 and 4: effort <-sample(0:4, 1000,replace= T) then I want to generate a conditional format : #(if effort=0 then return 4500,if effort=1 then return 4300, if effort=2 then return 3700, if effort=3 then return 4700, if effort=4 then return 5300)

so I wrote these code:

bso<- function(effort){
if(effort==0){return(4500)}
if(effort==1){return(4300)}
if(effort==2){return(3700)}
if(effort==3){return(4700)}
if(effort==4){return(5300)}}

#but it doesn't work! I don't know how can I fix it!

Aucun commentaire:

Enregistrer un commentaire