mercredi 3 avril 2019

R, problems using a for cycle inside a if else

i´m trying to check if all the elements inside a var are all the same, im using this code

if( isTRUE(for(i in 1:length(x)){x[1]==x[i]})){print(x[1])} else{print("several")

supose

x <- c(0,0,0,0,0,0,0,0,0,0,0) 

here the code should return "0" and if

x <- c(0,0,0,0,0,1,0,0,0,0,0) 

here it should return "several", in both cases i get "several", any idea why is not working as desired? tank u in advance

Aucun commentaire:

Enregistrer un commentaire