I would like to add a column to a column based on the values of the other columns in one column, e.g.
df < - data.frame (a = c (1,2,3), b = c (4,5,1)), & lt; - Data Eligible (df) G & LT; - Function (x, y) {if (y> gt) returns (list (1,2)) and return (list (2,1)) dt [, c ('x', 'y') = G (A, B)]
But these errors arise, and using IFLs does not work either.
you if (...)
else
Should use ifelse
instead. In addition there should be a list of length of return statement, in which each list element has the same length as x
and y
.
live < - Function (x, y) {list (ifelse (y>, x, 1, 2), ifelse (y> x, 2, 1))}
No comments:
Post a Comment