Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从标量中减去向量中的值。但是,如果结果小于零,我想将结果设置为零。
我试过使用max,但它没有给我预期的结果
max
s # [1] 750.0 975.0 1125.0 1237.5 1312.5 1400.0 max(1050 - s, 0) # [1] 300
我希望结果是c(300, 150, 0, 0, 0, 0)
c(300, 150, 0, 0, 0, 0)
我建议pmax:
pmax
pmax(1050 - s, 0) # [1] 300 75 0 0 0 0