tags:

views:

44

answers:

1

I want to apply the max operation to each column entry in R. But when I do the following, it applies the operation across all columns. Is there way to do this without using for loops?

> s
[1]  750.0  975.0 1125.0 1237.5 1312.5 1400.0
> max(1050-s,0)
[1] 300
## expect result to be (300 150  0  0  0  0)
+4  A: 

I suggest pmax:

> pmax(1050-s,0)
[1] 300  75   0   0   0   0
nullglob