Addition involving numeric(0) values

前端 未结 2 897
礼貌的吻别
礼貌的吻别 2021-01-21 01:33

Suppose x is a real number, or a vector. i is valued-False. Then x[i] will return numeric(0). I would like to treat this as a real number 0, or integer 0, which are both fit for

2条回答
  •  青春惊慌失措
    2021-01-21 01:54

    You can use max/min with 0 to get 0 as output when input is numeric(0).

    x <- 1:10
    max(x[FALSE], 0)
    #[1] 0
    
    min(x[FALSE], 0)
    #[1] 0
    

提交回复
热议问题