有没有办法计算 R 中 0 和 1 的序列?

Is there a way to count sequence of 0 and 1 in R?

我有以下数据作为 excel 文件:

X
0
0
1
1
0
0

我想统计出现以下序列的次数:

00
11
10
01

我想要以下输出:

序列计数

00 2
11 1
01 1
10 1

我尝试使用 count 但我无法想出任何有用的东西。 count.seq 用于类似目的,但它估计 DNA 或 RNA 序列数据。

x <- c(0, 0, 1, 1, 0, 0)
n <- length(x)
s <- paste0(x[-n], x[-1L])
s
## [1] "00" "01" "11" "10" "00"

table(factor(s, levels = c("00", "01", "10", "11")))
## 00 01 10 11 
##  2  1  1  1