library(raster)
## Loading required package: sp
xmn <- -10
xmx <- 20
ymn <- -30
ymx <- 50
r <- raster(extent(xmn, xmx, ymn, ymx), nrow = 30, ncol = 60)
N <- 1e5
xy <- data.frame(x = runif(N, xmn, xmx), y = runif(N, ymn, ymx))
## classify point by cell
xy$cell <- cellFromXY(r, cbind(xy$x, xy$y))
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## count point by cell
summ <- xy %>% 
  group_by(cell) %>% 
  tally()
## initialize default raster value
r <- setValues(r, NA)
## assign count to populated cells
r[summ$cell] <- summ$n

# equivalent
#rr <- rasterize(cbind(xy$x, xy$y), r, fun = "count")