Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

How to get the array with condition in R? [duplicate]

$
0
0

I have a data set something like this:

  ~product_name,   ~id,  ~clicks,
        "A",         1,      1,  
        "A",         4,      1, 
        "A",         3,      1, 
        "B",         4,      2, 
        "B",         6,      2, 
        "C",         3,      3, 
        "C",         5,      3, 
        "D",         6,      4, 
        "D",         4,      4, 
        "D",         3,      4, 
)

Now, I want to aggregate it by making an array list for the id. Here is my desired data:

df_A <- tribble(
  ~product_name,   ~id,      ~clicks,
        "A",         1,4,3,       1,  
        "B",         4,6,         2, 
        "C",         3,5,         3, 
        "D",         6,4,3,       4,
)

How can I do that?


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>