Capping each member in an r array -
i'm new r , have losses data:
losses=c(25,250,5,17,2,195,12,8,75,5,50,1);
how cap each member of list @ 150? namely how perform min(150,x)
each member of list?
then want cap losses @ 'amount of insurance' array:
aoi=c(150,250,100,125,300,200,80,250,100,350,500,120)
see ?pmin
, or parallel minima calculation:
pmin(150,losses) #[1] 25 150 5 17 2 150 12 8 75 5 50 1
if need multiple times, beneficial collect variables in data.frame
or list
. e.g.:
dat <- data.frame(losses,aoi) data.frame(map(pmin,dat,150)) # losses aoi #1 25 150 #2 150 150 #3 5 100 #etc...
Comments
Post a Comment