I would like to create a new column (PT) using base function in R for iris dataset which will display "Long" if the Petal Length is >=4 and "Short" if Petal Length is <4
I have written the below code, but it is giving me an error the condition has length > 1 and only the first element will be used. Can you please help me with this
When using an if-statement there is only one condition that can be true or false in order to run the if or not.
if(1 == 1){print("true")}
[1] "true"
If the output of the comparison generates more than one true or false, only the first one will be used to decide and you get the error
1 == 1:5
#> [1] TRUE FALSE FALSE FALSE FALSE
if(1 == 1:5){print("true")}
#> Warning in if (1 == 1:5) {: the condition has length > 1 and only the first
#> element will be used
#> [1] "true"