jeudi 29 juillet 2021

How apply a function in data frame with if/ lessthan statement in R?

I have a data frame looks like the following:

df<- data.frame(
  X1 = seq(from = 7, to = 25, by = 2),
  X2 = c(7,  10 ,11, 12, 16, 17, 20, 24, 2, 30),
  X3 = 2:11
)

I want to substitute column X3 with the following logic

if X1 lees than x2 then X3=0

Aucun commentaire:

Enregistrer un commentaire