Ok, the title may not be the most descriptive. It’s easier to explain with an example.
I have a data.frame like this:
A B 1 2
L M 3 0
P Q 5 6
I want to output an array of the cell in column 1 if col3 > col4, or the cell in col2 if col3 <= col4. The output vector from this data.frame would be B, L, Q.
I’m aware that I still haven’t explained my problem very well, so here is what it would look like in an imperative language:
vector = []
for each rows as row
if row[3] > row[4]
vector.add(row[1])
else
vector.add(row[2])
return vector
I apologise if this problem has already been answered, but unfortunately Google is not much of help when it comes to R questions.
Thanks,
Andreas
This should work (assuming
dfis your data frame)