Reputation: 55
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"))
Upvotes: 3
Views: 129
Reputation: 2443
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
Upvotes: 5