0

I want to count the total number of items in a vector greater than (>) the absolute value of 1.

vec <- c(5,3,-7,0,0,0,-1,0,3,1,-3,4,7)

the result should exclude 0, 1 and -1 in the count and return the total count of 7

attempt

sum(vec >abs(1))
# this returns '5' instead of '7'

Thanks

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
RayX500
  • 247
  • 2
  • 10
  • The problem was caused by a slip in the code and will probably help nobody else, hence, I'll cast a close vote. – Jan Jul 08 '21 at 19:58

1 Answers1

1

The abs should be on the 'vec' and not on 1

sum(abs(vec) > 1)
[1] 7
akrun
  • 874,273
  • 37
  • 540
  • 662