Typescript Array Count Function In R