mustafank
mustafank

Reputation: 17

Add column based on value in other column

Make a new column that is binary based on if chance.of.admit > 0.5

chance.of.admit is a variable in the data frame

Would I need to loop over chance? How would I go about looping over change and adding a new column with 1's and 0's? Is there a better way?

Upvotes: 0

Views: 41

Answers (2)

vitor taira
vitor taira

Reputation: 103

Another solution is:

df$binary <- ifelse(df$chance.of.admit>0.5, 1, 0)

Upvotes: 1

akrun
akrun

Reputation: 886938

We can use

df1$flag <- +(df1$chance.of.admit > 0.5)

Upvotes: 1

Related Questions