I would like to know how I can populate a column in a data.frame or data.table based on the value of other columns.
for example:
data.table(a = c(1:5), b = c(5:1), c = rep("",5))
a b c
1 5
2 4
3 3
4 2
5 1
I want to populate c to:
- indicate "More" if "a" is greater than "b"
- "Less" if "a" is less than "b"
- "Equal if they are equal
as below:
a b c
1 5 "Less"
2 4 "Less"
3 3 "Equal"
4 2 "More"
5 1 "More"
I know that this can be done through a for loop with multiple if statements, but I have a very large data set and I would like to do this using the "Apply" family of functions.
Any help would be greatly appreciated.