r - Count the number of elements in an array fulfilling a simple condition -
i jumping r after long time away , surprised how simple of things do. have created 3 arrays:
xs = runif(n, min=-1, max=1); ys = runif(n, min=-1, max=1); rs = sqrt( xs^2 + ys^2 );
where, obviously, x , y (together) define n points within (-1,1) square , r vector defining distances of these points.
if want count number of elements in rs
less or equal 1, there simple inl-line command this?
sum( rs <= 1 )
rs <= 1
yields logical vector. true
equals 1; false
equals 0.
arrays r
No comments:
Post a Comment