gisol
gisol

Reputation: 754

Change all values in one column of a dataframe lower than X to 0, and X and all values greater than X to 1

I'm sure this is simple but my R isn't up to it: how can I change all values in one column of a dataframe lower than X to 0, and X and all values greater than X to 1?

Upvotes: 1

Views: 8106

Answers (1)

David Robinson
David Robinson

Reputation: 78610

The ifelse function does exactly what you want. If your dataframe is called d, and the column called d$column:

d$column = ifelse(d$column < X, 0, 1)

Upvotes: 4

Related Questions