IF and then function in R

You have given us very little information to work with. Please make a Reproducible Example if the code below does not fix your problem. To learn about reproducible examples, you can read this post:

Let's assume you have a data frame named DF and a variable named MyVar. This code makes a new column in DF named alpha with a value of 1 in every row if MyVar is equal to alpha.

if (MyVar == "alpha") {
  DF$alpha <- 1
}
1 Like