Compare and group 2 data

Hello,
Firstable, sorry for my English (i'm french)

First i've a vector : liste1<-c(1:9)

Second a table (1 column) (table$vect) :
1
4
7
4
2
1
8

What did I need to do (how many times appears a number in the data)
1 2
2 1
3 0
4 2
5 0
6 0
7 1
8 1
9 0

I've found "sort" but the result is :
1 2
4 2
2 1
7 1
8 1

How can i do this ? Thank you for your help

Here is one solution.

DF <- data.frame(VEC = c(1, 4, 7, 4, 2, 1,8))
MyFunc <- function(V) sum(V == DF$VEC)
sapply(1:9, MyFunc)
#> [1] 2 1 0 2 0 0 1 1 0

Created on 2020-11-07 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.