This is the simplified dataset I created to illustrate my question.
Hello all, I'm trying to reference a column in a dataframe Database
. My goal is to be able to reference, say, the Weight
column and from that populate the Risk
and Overweight
columns. Here is what I'm trying (along with other failed code):
ifelse(Database[,"Weight"] >190, Database$Risk="HIGH", Database$Risk="LOW")
Error: unexpected '=' in "ifelse(Database[,"Weight"] >190, Database$Risk="
I have also tried doing groups of code with the if()
command.
if(Database$Weight > 190) {Database$Risk="HIGH"; Database$Overweight="YES"}
Error in if (Database$Weight > 190) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In Ops.factor(Database$Weight, 190) : ‘>’ not meaningful for factors
2: In if (Database$Weight > 190) { :
the condition has length > 1 and only the first element will be used
...Which clearly I'm not doing correctly.
The ideal output of this code would resemble this: