I have a data frame like this:
user event score
1 2 0.5
1 3 0.2
2 3 0.7
3 1 0.9
3 4 0.1
and I want to get the result:
user event
1 2,3
2 3
3 1,4
How can I do this in R?
Sometimes, I think R’s lacking of base data structures in programming languages such as Java or Python makes my work inconvinient.
Assuming your
data.frameis calledmydata, do:to get a list that retains the numeric representation or
Which pastes the values to create a character vector.
Here’s a demonstration of how these are stored differently:
I personally prefer using
Itopasteso that I can uselapply()on that column if I need to later.