[R] ifelse for creating discriminating variable based on two conditions
andreas.nord at biol.lu.se
Fri Oct 14 08:17:21 CEST 2016
Apologies for a likely naive question.
I am trying to create a discriminating dummy variable using 'ifelse' based on conditions in two variables.
Specifically, I want to assign levels in a new factor as '0' or '1' based on a user-defined cut off. I.e. something similar to:
Which is all straightforward.
But how do I go on to assign values in variable 'molecule'based on the same cut off, but separately for each level of a second variable, in this case the factor 'fruit' with three levels. That is, how do I derive fruit-specific cut-offs using a data frame with the general structure of that below?
Many thanks in advance!
[[alternative HTML version deleted]]
More information about the R-help