SuchARush
SuchARush

Reputation: 41

Using factors to write new columns in R

I have a table with 8 variables, one of them is a factor with 3 levels. I want to write something in a new column based on which of the the levels but can't figure it out.

if(Nitro[Nitro$Result == "push", ]){
    Nitro$Profit <- 0
}

Upvotes: 0

Views: 36

Answers (1)

User981636
User981636

Reputation: 3621

If you are using data frames, this should work.

 Nitro$Profit[Nitro$Result == "push"] <- 0

If you are using data table, try:

Nitro[Result == "push", Profit := 0]

Upvotes: 2

Related Questions