if (crabs$FL >= median(crabs$FL)) {crabs$FLG <- "L"} else {crabs$FLG <- "S"}
crabs is the data name and FL is a variable name. I am trying to create a variable name "FLG" if FL is greater than median.
But it says the condition has length > 1 and only the first element will be used. It created FLG but it seems like only the first row's value is used to create it.
if (crabs$FL[i] >= median(crabs$FL)) {crabs$FLG <- "L"} else {crabs$FLG <- "S"}
I tried this one. But now it says Error in if (crabs$FL[i] >= median(crabs$FL)) { : missing value where TRUE/FALSE needed.
Give me any idea to fix this error please!!