dimanche 5 septembre 2021

the if else function is executing using length>1 [closed]

Marks <- sample(x = 100:300,size = 200,replace = T)

as.vector(Marks)

Gender <- sample(x = c("Male","Female"),size = 200,replace = T,prob =  c(0.4,0.6))

as.vector(Gender)

weight <- sample(x = 40:60,size = 200,replace = T)

as.vector(weight)

Students <-data.frame(Marks, Gender)

Students$Groups <- (if(Students$Marks >200 && Students$Gender =="Male"){

print("A")}

else if(Students$Marks >200 && Students$Gender =="Female"){

print("B")}

else if(Students$Marks <=200 && Students$Gender =="Male"){

print("C")}

else if(Students$Marks <=200 && Students$Gender =="Female"){

print("D")})

Aucun commentaire:

Enregistrer un commentaire