Convert values below a threshold into 1

前端 未结 3 583
离开以前
离开以前 2021-01-13 19:47

Let\'s say if I have the following data

x <- rnorm(100)

I want to create another column where where if x is equal to or gre

3条回答
  •  孤街浪徒
    2021-01-13 20:29

    You want to use an Heaviside function. You can find it in the fbasics package, for example.

    set.seed(42)
    x <- rnorm(100)
    library(fBasics)
    Heaviside(x, 0.2)
    

提交回复
热议问题