# Solved – Combine multiple rows into one row in R

I am creating a sample of 3 observations with 3 values. I would like to then combine them into one observation and determine the frequency of duplicate values but would like to know what values are duplicated how many times. For example, "59741111" is duplicated 3 times and "29611022" is duplicated twice. Thank you very much.

``set.seed(10231995)  df <- t(replicate(3, sample(id, 3, replace=FALSE, prob=NULL))) df ``

Result
[,1] [,2] [,3]
[1,] "59741111" "73380703" "29611022"
[2,] "59741111" "70470420" "59741111"
[3,] "33360105" "29611022" "32080517"

Desired result

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
"59741111" "73380703" "29611022" "59741111" "70470420" "59741111" "33360105" "29611022" "32080517"

Value freq rel freq

"59741111" 3 .33

"29611022" 2 .22

Contents

``require(data.table) set.seed(10231995)   id <- 1:5 df <- data.table(t(replicate(3, sample(id, 3, replace=FALSE, prob=NULL)))) df  df2 <- melt(df) df2  df2[, .N, by=value] ``