3

I am working with the following problem. I have a list with different size and I wanna count the occurrence of the words but join the same combinations like that:

[[1]]
"Room" "Residential 
[[2]]
"Residential" "Room" 
[[3]]
"Garage"
[[4]]
"Room" "Residential" "Comercial"

Results - combn | value

'Room, Residential': 2
'Garage': 1
"Room, Residential, Comercial': 1

Any ideas?

DATA

list(c("Room", "Residential"), c("Residential", "Room"), "Garage", 
     c("Room", "Residential", "Comercial"))
jazzurro
  • 23,179
  • 35
  • 66
  • 76
  • 2
    What about a reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – s_baldur Dec 14 '18 at 13:37

1 Answers1

5
res = lapply(L, function(x) paste(sort(unique(x)), collapse = ","))

This will sort the values according to some order and combine the values with a comma, where L is your list;

table(unlist(res))

This will give you the number of unique combinations

Omry Atia
  • 2,411
  • 2
  • 14
  • 27