I'm attempting to create a data table with many columns, but cannot think of a way to do this succinctly (using dplyr
or something else). Let's consider this data:
URL TERM
google.com dog
yahoo.com cat
bing.com hamster
google.com dog
google.com cat
yahoo.com cat
bing.com dog
yahoo.com cat
I would like to end with something like this:
URL dog cat hamster
google.com 2 1 0
yahoo.com 0 3 0
bing.com 1 0 1
This is something that I can achieve using for
loops... but I might as well not use R. Basically, I'd like to group by URL
, create a new column for each unique TERM
value, wherein each column contains a count of said TERM
for each URL
.
Any ideas?